WIFI-1601: Bulk Send for SSID Profile provision

WIFI-1602: Change configuration order to reduce UCI resets
This commit is contained in:
Mike Hansen
2021-02-18 17:30:50 -05:00
parent aefc799975
commit 85bf7e8f98
7 changed files with 526 additions and 790 deletions

View File

@@ -1,21 +1,5 @@
package com.telecominfraproject.wlan.opensync.ovsdb;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import javax.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import com.google.common.collect.ImmutableMap;
import com.telecominfraproject.wlan.core.model.equipment.MacAddress;
import com.telecominfraproject.wlan.core.model.equipment.RadioType;
@@ -24,28 +8,27 @@ import com.telecominfraproject.wlan.opensync.external.integration.OpensyncExtern
import com.telecominfraproject.wlan.opensync.external.integration.OvsdbClientInterface;
import com.telecominfraproject.wlan.opensync.external.integration.OvsdbSession;
import com.telecominfraproject.wlan.opensync.external.integration.OvsdbSessionMapInterface;
import com.telecominfraproject.wlan.opensync.external.integration.models.ConnectNodeInfo;
import com.telecominfraproject.wlan.opensync.external.integration.models.OpensyncAPConfig;
import com.telecominfraproject.wlan.opensync.external.integration.models.OpensyncAPInetState;
import com.telecominfraproject.wlan.opensync.external.integration.models.OpensyncAPVIFState;
import com.telecominfraproject.wlan.opensync.external.integration.models.OpensyncWifiAssociatedClients;
import com.telecominfraproject.wlan.opensync.external.integration.models.*;
import com.telecominfraproject.wlan.opensync.ovsdb.dao.OvsdbDao;
import com.telecominfraproject.wlan.opensync.util.OvsdbStringConstants;
import com.telecominfraproject.wlan.opensync.util.SslUtil;
import com.vmware.ovsdb.callback.ConnectionCallback;
import com.vmware.ovsdb.callback.MonitorCallback;
import com.vmware.ovsdb.exception.OvsdbClientException;
import com.vmware.ovsdb.protocol.methods.MonitorRequest;
import com.vmware.ovsdb.protocol.methods.MonitorRequests;
import com.vmware.ovsdb.protocol.methods.MonitorSelect;
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.methods.*;
import com.vmware.ovsdb.protocol.operation.notation.Row;
import com.vmware.ovsdb.service.OvsdbClient;
import com.vmware.ovsdb.service.OvsdbPassiveConnectionListener;
import io.netty.handler.ssl.SslContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.security.cert.X509Certificate;
import java.util.*;
import java.util.concurrent.CompletableFuture;
@Profile("ovsdb_manager")
@Component
@@ -65,9 +48,6 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
@org.springframework.beans.factory.annotation.Value("${tip.wlan.defaultCommandDurationSec:3600}")
private long defaultCommandDurationSec;
@org.springframework.beans.factory.annotation.Value("${tip.wlan.defaultCommandDelaySec:60}")
private long defaultCommandDelaySec;
@Autowired
private SslContext sslContext;
@@ -100,7 +80,7 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
String remoteHost = ovsdbClient.getConnectionInfo().getRemoteAddress().getHostAddress();
int localPort = ovsdbClient.getConnectionInfo().getLocalPort();
String subjectDn = null;
String subjectDn;
try {
subjectDn = ((X509Certificate) ovsdbClient.getConnectionInfo().getRemoteCertificate())
.getSubjectDN().getName();
@@ -118,8 +98,7 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
extIntegrationInterface.apConnected(key, connectNodeInfo);
// push configuration to AP
connectNodeInfo = processConnectRequest(ovsdbClient, clientCn, connectNodeInfo);
processConnectRequest(ovsdbClient, clientCn, connectNodeInfo);
monitorOvsdbStateTables(ovsdbClient, key);
@@ -130,12 +109,10 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
LOG.error("autoprovisioning error {}", e.getMessage(), e);
// something is wrong with the SSL
ovsdbClient.shutdown();
return;
} catch (Exception e) {
LOG.error("ovsdbClient error", e);
// something is wrong with the SSL
ovsdbClient.shutdown();
return;
}
}
@@ -184,7 +161,7 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
try {
ovsdbClient.shutdown();
} catch (Exception e) {
LOG.info("Caught Exception shutting down ovsdb client, may have already been disconnected {}",
LOG.error("Caught Exception shutting down ovsdb client, may have already been disconnected",
e);
}
@@ -199,8 +176,8 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
LOG.info("Manager waiting for connection on port {}...", ovsdbListenPort);
}
private ConnectNodeInfo processConnectRequest(OvsdbClient ovsdbClient, String clientCn,
ConnectNodeInfo connectNodeInfo) {
private void processConnectRequest(OvsdbClient ovsdbClient, String clientCn,
ConnectNodeInfo connectNodeInfo) {
LOG.debug("Starting Client connect");
connectNodeInfo = ovsdbDao.updateConnectNodeInfoOnConnect(ovsdbClient, clientCn, connectNodeInfo,
@@ -224,17 +201,16 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
if (opensyncAPConfig != null) {
ovsdbDao.configureNtpServer(ovsdbClient, opensyncAPConfig);
ovsdbDao.configureWifiRadios(ovsdbClient, opensyncAPConfig);
ovsdbDao.configureWifiRrm(ovsdbClient, opensyncAPConfig);
ovsdbDao.configureGreTunnels(ovsdbClient, opensyncAPConfig);
ovsdbDao.createVlanNetworkInterfaces(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);
if (ovsdbDao.getDeviceStatsReportingInterval(ovsdbClient) != collectionIntervalSecDeviceStats) {
@@ -247,7 +223,6 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
}
LOG.debug("Client connect Done");
return connectNodeInfo;
}
@Override
@@ -267,9 +242,7 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
throw new IllegalStateException("AP with id " + apId + " is not connected");
}
String ret = ovsdbDao.changeRedirectorAddress(ovsdbSession.getOvsdbClient(), apId, newRedirectorAddress);
return ret;
return ovsdbDao.changeRedirectorAddress(ovsdbSession.getOvsdbClient(), apId, newRedirectorAddress);
}
@Override
@@ -293,11 +266,9 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
ovsdbDao.removeAllSsids(ovsdbClient); // always
ovsdbDao.removeAllInetConfigs(ovsdbClient);
ovsdbDao.removeWifiRrm(ovsdbClient);
ovsdbDao.removeAllStatsConfigs(ovsdbClient); // always
extIntegrationInterface.clearEquipmentStatus(apId);
ovsdbDao.configureNtpServer(ovsdbClient, opensyncAPConfig);
ovsdbDao.configureWifiRadios(ovsdbClient, opensyncAPConfig);
ovsdbDao.configureWifiRrm(ovsdbClient, opensyncAPConfig);
ovsdbDao.configureGreTunnels(ovsdbClient, opensyncAPConfig);
ovsdbDao.createVlanNetworkInterfaces(ovsdbClient, opensyncAPConfig);
@@ -308,12 +279,7 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
}
ovsdbDao.configureInterfaces(ovsdbClient);
ovsdbDao.configureStatsFromProfile(ovsdbClient, opensyncAPConfig);
if (ovsdbDao.getDeviceStatsReportingInterval(ovsdbClient) != collectionIntervalSecDeviceStats) {
ovsdbDao.updateDeviceStatsReportingInterval(ovsdbClient, collectionIntervalSecDeviceStats);
}
ovsdbDao.updateEventReportingInterval(ovsdbClient, collectionIntervalSecEvent);
ovsdbDao.configureWifiRadios(ovsdbClient, opensyncAPConfig);
LOG.debug("Finished processConfigChanged for {}", apId);
}
@@ -404,75 +370,64 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
OvsdbDao.dhcpLeasedIpDbTable + "_" + key,
new MonitorRequests(ImmutableMap.of(OvsdbDao.dhcpLeasedIpDbTable,
new MonitorRequest(new MonitorSelect(true, true, true, true)))),
new MonitorCallback() {
tableUpdates -> {
try {
LOG.info(OvsdbDao.dhcpLeasedIpDbTable + "_" + key + " monitor callback received {}",
tableUpdates);
@Override
public void update(TableUpdates tableUpdates) {
try {
LOG.info(OvsdbDao.dhcpLeasedIpDbTable + "_" + key + " monitor callback received {}",
tableUpdates);
List<Map<String, String>> insert = new ArrayList<>();
List<Map<String, String>> delete = new ArrayList<>();
List<Map<String, String>> update = new ArrayList<>();
List<Map<String, String>> insert = new ArrayList<>();
List<Map<String, String>> delete = new ArrayList<>();
List<Map<String, String>> update = new ArrayList<>();
for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) {
for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) {
for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) {
for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) {
if (rowUpdate.getNew() == null) {
Map<String, String> rowMap = new HashMap<>();
if (rowUpdate.getNew() == null) {
Map<String, String> rowMap = new HashMap<>();
rowUpdate.getOld().getColumns().entrySet().forEach(c -> OvsdbDao.translateDhcpFpValueToString(c, rowMap));
rowUpdate.getOld().getColumns().entrySet().stream().forEach(c -> {
OvsdbDao.translateDhcpFpValueToString(c, rowMap);
});
delete.add(rowMap);
// delete
} else if (rowUpdate.getOld() == null) {
// insert
Map<String, String> rowMap = new HashMap<>();
delete.add(rowMap);
// delete
} else if (rowUpdate.getOld() == null) {
// insert
Map<String, String> rowMap = new HashMap<>();
rowUpdate.getNew().getColumns().entrySet().forEach(c -> OvsdbDao.translateDhcpFpValueToString(c, rowMap));
rowUpdate.getNew().getColumns().entrySet().stream().forEach(c -> {
OvsdbDao.translateDhcpFpValueToString(c, rowMap);
});
insert.add(rowMap);
} else {
insert.add(rowMap);
} else {
// insert
Map<String, String> rowMap = new HashMap<>();
// insert
Map<String, String> rowMap = new HashMap<>();
rowUpdate.getOld().getColumns().putAll(rowUpdate.getNew().getColumns());
rowUpdate.getOld().getColumns().entrySet().forEach(c -> OvsdbDao.translateDhcpFpValueToString(c, rowMap));
rowUpdate.getOld().getColumns().putAll(rowUpdate.getNew().getColumns());
rowUpdate.getOld().getColumns().entrySet().stream().forEach(c -> {
OvsdbDao.translateDhcpFpValueToString(c, rowMap);
});
update.add(rowMap);
update.add(rowMap);
}
}
}
if (!insert.isEmpty()) {
extIntegrationInterface.dhcpLeasedIpDbTableUpdate(insert, key,
RowUpdateOperation.INSERT);
}
if (!delete.isEmpty()) {
extIntegrationInterface.dhcpLeasedIpDbTableUpdate(delete, key,
RowUpdateOperation.DELETE);
}
if (!update.isEmpty()) {
extIntegrationInterface.dhcpLeasedIpDbTableUpdate(update, key,
RowUpdateOperation.MODIFY);
}
} catch (Exception e) {
LOG.error("dhcpLeasedIpDbTableUpdate failed", e);
}
if (!insert.isEmpty()) {
extIntegrationInterface.dhcpLeasedIpDbTableUpdate(insert, key,
RowUpdateOperation.INSERT);
}
if (!delete.isEmpty()) {
extIntegrationInterface.dhcpLeasedIpDbTableUpdate(delete, key,
RowUpdateOperation.DELETE);
}
if (!update.isEmpty()) {
extIntegrationInterface.dhcpLeasedIpDbTableUpdate(update, key,
RowUpdateOperation.MODIFY);
}
} catch (Exception e) {
LOG.error("dhcpLeasedIpDbTableUpdate failed", e);
}
});
@@ -486,75 +441,64 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
CompletableFuture<TableUpdates> csCf = ovsdbClient.monitor(OvsdbDao.ovsdbName,
OvsdbDao.commandStateDbTable + "_" + key,
new MonitorRequests(ImmutableMap.of(OvsdbDao.commandStateDbTable, new MonitorRequest())),
new MonitorCallback() {
tableUpdates -> {
try {
LOG.info(OvsdbDao.commandStateDbTable + "_" + key + " monitor callback received {}",
tableUpdates);
@Override
public void update(TableUpdates tableUpdates) {
try {
LOG.info(OvsdbDao.commandStateDbTable + "_" + key + " monitor callback received {}",
tableUpdates);
List<Map<String, String>> insert = new ArrayList<>();
List<Map<String, String>> delete = new ArrayList<>();
List<Map<String, String>> update = new ArrayList<>();
List<Map<String, String>> insert = new ArrayList<>();
List<Map<String, String>> delete = new ArrayList<>();
List<Map<String, String>> update = new ArrayList<>();
for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) {
for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) {
for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) {
for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) {
if (rowUpdate.getNew() == null) {
Map<String, String> rowMap = new HashMap<>();
if (rowUpdate.getNew() == null) {
Map<String, String> rowMap = new HashMap<>();
rowUpdate.getOld().getColumns().forEach((key1, value) -> rowMap.put(key1, value.toString()));
rowUpdate.getOld().getColumns().entrySet().stream().forEach(c -> {
rowMap.put(c.getKey(), c.getValue().toString());
});
delete.add(rowMap);
// delete
} else if (rowUpdate.getOld() == null) {
// insert
Map<String, String> rowMap = new HashMap<>();
delete.add(rowMap);
// delete
} else if (rowUpdate.getOld() == null) {
// insert
Map<String, String> rowMap = new HashMap<>();
rowUpdate.getNew().getColumns().forEach((key1, value) -> rowMap.put(key1, value.toString()));
rowUpdate.getNew().getColumns().entrySet().stream().forEach(c -> {
rowMap.put(c.getKey(), c.getValue().toString());
});
insert.add(rowMap);
} else {
insert.add(rowMap);
} else {
// insert
Map<String, String> rowMap = new HashMap<>();
// insert
Map<String, String> rowMap = new HashMap<>();
rowUpdate.getOld().getColumns().putAll(rowUpdate.getNew().getColumns());
rowUpdate.getOld().getColumns().forEach((key1, value) -> rowMap.put(key1, value.toString()));
rowUpdate.getOld().getColumns().putAll(rowUpdate.getNew().getColumns());
rowUpdate.getOld().getColumns().entrySet().stream().forEach(c -> {
rowMap.put(c.getKey(), c.getValue().toString());
});
update.add(rowMap);
update.add(rowMap);
}
}
}
if (!insert.isEmpty()) {
extIntegrationInterface.commandStateDbTableUpdate(insert, key,
RowUpdateOperation.INSERT);
}
if (!delete.isEmpty()) {
extIntegrationInterface.commandStateDbTableUpdate(delete, key,
RowUpdateOperation.DELETE);
}
if (!update.isEmpty()) {
extIntegrationInterface.commandStateDbTableUpdate(update, key,
RowUpdateOperation.MODIFY);
}
} catch (Exception e) {
LOG.error("commandStateDbTableUpdate failed", e);
}
if (!insert.isEmpty()) {
extIntegrationInterface.commandStateDbTableUpdate(insert, key,
RowUpdateOperation.INSERT);
}
if (!delete.isEmpty()) {
extIntegrationInterface.commandStateDbTableUpdate(delete, key,
RowUpdateOperation.DELETE);
}
if (!update.isEmpty()) {
extIntegrationInterface.commandStateDbTableUpdate(update, key,
RowUpdateOperation.MODIFY);
}
} catch (Exception e) {
LOG.error("commandStateDbTableUpdate failed", e);
}
});
@@ -567,21 +511,16 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
CompletableFuture<TableUpdates> awCf = ovsdbClient.monitor(
OvsdbDao.ovsdbName, OvsdbDao.awlanNodeDbTable + "_" + key, new MonitorRequests(ImmutableMap
.of(OvsdbDao.awlanNodeDbTable, new MonitorRequest(new MonitorSelect(true, true, true, true)))),
new MonitorCallback() {
tableUpdates -> {
try {
LOG.info(OvsdbDao.awlanNodeDbTable + "_" + key + " monitor callback received {}",
tableUpdates);
@Override
public void update(TableUpdates tableUpdates) {
try {
LOG.info(OvsdbDao.awlanNodeDbTable + "_" + key + " monitor callback received {}",
tableUpdates);
extIntegrationInterface.awlanNodeDbTableUpdate(
ovsdbDao.getOpensyncAWLANNode(tableUpdates, key, ovsdbClient), key);
} catch (Exception e) {
LOG.error("awlanNodeDbTableUpdate failed", e);
}
extIntegrationInterface.awlanNodeDbTableUpdate(
ovsdbDao.getOpensyncAWLANNode(tableUpdates, key, ovsdbClient), key);
} catch (Exception e) {
LOG.error("awlanNodeDbTableUpdate failed", e);
}
});
extIntegrationInterface.awlanNodeDbTableUpdate(ovsdbDao.getOpensyncAWLANNode(awCf.join(), key, ovsdbClient),
@@ -592,45 +531,40 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
CompletableFuture<TableUpdates> acCf = ovsdbClient.monitor(OvsdbDao.ovsdbName,
OvsdbDao.wifiAssociatedClientsDbTable + "_" + key,
new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiAssociatedClientsDbTable, new MonitorRequest())),
new MonitorCallback() {
tableUpdates -> {
@Override
public void update(TableUpdates tableUpdates) {
try {
LOG.info(
OvsdbDao.wifiAssociatedClientsDbTable + "_" + key + " monitor callback received {}",
tableUpdates);
try {
LOG.info(
OvsdbDao.wifiAssociatedClientsDbTable + "_" + key + " monitor callback received {}",
tableUpdates);
List<OpensyncWifiAssociatedClients> associatedClients = new ArrayList<>();
List<OpensyncWifiAssociatedClients> associatedClients = new ArrayList<>();
for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) {
for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) {
for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) {
if ((rowUpdate.getOld() != null) && (rowUpdate.getNew() == null)) {
Row row = rowUpdate.getOld();
String deletedClientMac = row.getStringColumn("mac");
// take care of the deletes as we go
// through
// the updates, as we want to delete
// before
// adding anyway.
extIntegrationInterface.wifiAssociatedClientsDbTableDelete(deletedClientMac,
key);
} else {
associatedClients.addAll(
ovsdbDao.getOpensyncWifiAssociatedClients(rowUpdate, key, ovsdbClient));
}
for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) {
if ((rowUpdate.getOld() != null) && (rowUpdate.getNew() == null)) {
Row row = rowUpdate.getOld();
String deletedClientMac = row.getStringColumn("mac");
// take care of the deletes as we go
// through
// the updates, as we want to delete
// before
// adding anyway.
extIntegrationInterface.wifiAssociatedClientsDbTableDelete(deletedClientMac,
key);
} else {
associatedClients.addAll(
ovsdbDao.getOpensyncWifiAssociatedClients(rowUpdate, key, ovsdbClient));
}
}
// now address the update/add
extIntegrationInterface.wifiAssociatedClientsDbTableUpdate(associatedClients, key);
} catch (Exception e) {
LOG.error("wifiAssociatedClientsDbTableUpdate failed", e);
}
// now address the update/add
extIntegrationInterface.wifiAssociatedClientsDbTableUpdate(associatedClients, key);
} catch (Exception e) {
LOG.error("wifiAssociatedClientsDbTableUpdate failed", e);
}
});
@@ -645,42 +579,35 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
OvsdbDao.wifiInetStateDbTable + "_" + key,
new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiInetStateDbTable,
new MonitorRequest(new MonitorSelect(true, true, true, true)))),
new MonitorCallback() {
tableUpdates -> {
try {
LOG.info(OvsdbDao.wifiInetStateDbTable + "_" + key + " monitor callback received {}", tableUpdates);
@Override
public void update(TableUpdates tableUpdates) {
try {
LOG.info(OvsdbDao.ovsdbName,
OvsdbDao.wifiInetStateDbTable + "_" + key + " monitor callback received {}",
tableUpdates);
List<OpensyncAPInetState> inetStateInsertOrUpdate = new ArrayList<>();
List<OpensyncAPInetState> inetStateDelete = new ArrayList<>();
List<OpensyncAPInetState> inetStateInsertOrUpdate = new ArrayList<>();
List<OpensyncAPInetState> inetStateDelete = new ArrayList<>();
for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) {
for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) {
for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) {
if (rowUpdate.getNew() == null) {
inetStateDelete.addAll(ovsdbDao.getOpensyncApInetStateForRowUpdate(rowUpdate,
key, ovsdbClient));
} else {
inetStateInsertOrUpdate.addAll(ovsdbDao
.getOpensyncApInetStateForRowUpdate(rowUpdate, key, ovsdbClient));
}
for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) {
if (rowUpdate.getNew() == null) {
inetStateDelete.addAll(ovsdbDao.getOpensyncApInetStateForRowUpdate(rowUpdate,
key, ovsdbClient));
} else {
inetStateInsertOrUpdate.addAll(ovsdbDao
.getOpensyncApInetStateForRowUpdate(rowUpdate, key, ovsdbClient));
}
}
// delete first
extIntegrationInterface.wifiInetStateDbTableUpdate(inetStateDelete, key);
// now process updates and mutations
extIntegrationInterface.wifiInetStateDbTableUpdate(inetStateInsertOrUpdate, key);
} catch (Exception e) {
LOG.error("wifiInetStateDbTableUpdate failed", e);
}
// delete first
extIntegrationInterface.wifiInetStateDbTableUpdate(inetStateDelete, key);
// now process updates and mutations
extIntegrationInterface.wifiInetStateDbTableUpdate(inetStateInsertOrUpdate, key);
} catch (Exception e) {
LOG.error("wifiInetStateDbTableUpdate failed", e);
}
});
@@ -696,21 +623,16 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
OvsdbDao.wifiRadioStateDbTable + "_" + key,
new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiRadioStateDbTable,
new MonitorRequest(new MonitorSelect(true, true, true, true)))),
new MonitorCallback() {
tableUpdates -> {
try {
LOG.info(OvsdbDao.wifiRadioStateDbTable + "_" + key + " monitor callback received {}",
tableUpdates);
@Override
public void update(TableUpdates tableUpdates) {
try {
LOG.info(OvsdbDao.wifiRadioStateDbTable + "_" + key + " monitor callback received {}",
tableUpdates);
extIntegrationInterface.wifiRadioStatusDbTableUpdate(
ovsdbDao.getOpensyncAPRadioState(tableUpdates, key, ovsdbClient), key);
} catch (Exception e) {
LOG.error("wifiRadioStatusDbTableUpdate failed", e);
}
extIntegrationInterface.wifiRadioStatusDbTableUpdate(
ovsdbDao.getOpensyncAPRadioState(tableUpdates, key, ovsdbClient), key);
} catch (Exception e) {
LOG.error("wifiRadioStatusDbTableUpdate failed", e);
}
});
extIntegrationInterface
.wifiRadioStatusDbTableUpdate(ovsdbDao.getOpensyncAPRadioState(rsCf.join(), key, ovsdbClient), key);
@@ -722,49 +644,44 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
.monitor(OvsdbDao.ovsdbName, OvsdbDao.wifiVifStateDbTable + "_" + key,
new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiVifStateDbTable,
new MonitorRequest(new MonitorSelect(false, true, true, true)))),
new MonitorCallback() {
tableUpdates -> {
try {
LOG.info(OvsdbDao.wifiVifStateDbTable + "_" + key + " monitor callback received {}",
tableUpdates);
@Override
public void update(TableUpdates tableUpdates) {
try {
LOG.info(OvsdbDao.wifiVifStateDbTable + "_" + key + " monitor callback received {}",
tableUpdates);
List<OpensyncAPVIFState> vifsToDelete = new ArrayList<>();
List<OpensyncAPVIFState> vifsToInsertOrUpdate = new ArrayList<>();
for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) {
List<OpensyncAPVIFState> vifsToDelete = new ArrayList<>();
List<OpensyncAPVIFState> vifsToInsertOrUpdate = new ArrayList<>();
for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) {
for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) {
for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) {
if (rowUpdate.getNew() == null) {
// this is a deletion
vifsToDelete.addAll(ovsdbDao.getOpensyncApVifStateForRowUpdate(
rowUpdate, key, ovsdbClient));
if (rowUpdate.getNew() == null) {
// this is a deletion
vifsToDelete.addAll(ovsdbDao.getOpensyncApVifStateForRowUpdate(
rowUpdate, key, ovsdbClient));
} else {
// either an insert or
// mutuate/update
vifsToInsertOrUpdate.addAll(ovsdbDao.getOpensyncApVifStateForRowUpdate(
rowUpdate, key, ovsdbClient));
} else {
// either an insert or
// mutuate/update
vifsToInsertOrUpdate.addAll(ovsdbDao.getOpensyncApVifStateForRowUpdate(
rowUpdate, key, ovsdbClient));
}
}
// delete first, if required
if (!vifsToDelete.isEmpty()) {
extIntegrationInterface.wifiVIFStateDbTableDelete(vifsToDelete, key);
}
if (!vifsToInsertOrUpdate.isEmpty()) {
extIntegrationInterface.wifiVIFStateDbTableUpdate(vifsToInsertOrUpdate,
key);
}
}
} catch (Exception e) {
LOG.error("wifiVIFStateDbTableUpdate failed", e);
}
// delete first, if required
if (!vifsToDelete.isEmpty()) {
extIntegrationInterface.wifiVIFStateDbTableDelete(vifsToDelete, key);
}
if (!vifsToInsertOrUpdate.isEmpty()) {
extIntegrationInterface.wifiVIFStateDbTableUpdate(vifsToInsertOrUpdate,
key);
}
}
} catch (Exception e) {
LOG.error("wifiVIFStateDbTableUpdate failed", e);
}
});
@@ -776,24 +693,20 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
CompletableFuture<TableUpdates> nsCf = ovsdbClient.monitor(
OvsdbDao.ovsdbName, OvsdbDao.nodeStateTable + "_" + key, new MonitorRequests(ImmutableMap
.of(OvsdbDao.nodeStateTable, new MonitorRequest(new MonitorSelect(true, true, true, true)))),
new MonitorCallback() {
@Override
public void update(TableUpdates tableUpdates) {
LOG.info(OvsdbDao.nodeStateTable + "_" + key + " monitor callback received {}");
tableUpdates.getTableUpdates().entrySet().stream().forEach(t -> {
LOG.info("TableUpdate for {}", t.getKey());
t.getValue().getRowUpdates().values().stream().forEach(r -> {
if (r.getOld() != null) {
LOG.info("Node_State old row {}", r.getOld().getColumns());
}
if (r.getNew() != null) {
LOG.info("Node_State new row {}", r.getNew().getColumns());
}
});
tableUpdates -> {
LOG.info(OvsdbDao.nodeStateTable + "_" + key + " monitor callback received {}");
tableUpdates.getTableUpdates().forEach((key1, value) -> {
LOG.info("TableUpdate for {}", key1);
value.getRowUpdates().values().forEach(r -> {
if (r.getOld() != null) {
LOG.info("Node_State old row {}", r.getOld().getColumns());
}
if (r.getNew() != null) {
LOG.info("Node_State new row {}", r.getNew().getColumns());
}
});
}
});
});
nsCf.join();
}
@@ -875,10 +788,8 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
try {
OvsdbSession session = ovsdbSessionMapInterface.getSession(apId);
OvsdbClient ovsdbClient = session.getOvsdbClient();
Map<String, String> payload = new HashMap<>();
ovsdbDao.configureCommands(ovsdbClient, OvsdbDao.StopDebugEngineApCommand, payload, Long.valueOf(0L),
Long.valueOf(0L));
ovsdbDao.configureCommands(ovsdbClient, OvsdbDao.StopDebugEngineApCommand, payload, 0L, 0L);
LOG.debug("TipWlanOvsdbClient::stopDebugEngine Stop debug engine on AP {}", apId);
return "Stop debug engine on AP " + apId;

View File

@@ -53,7 +53,7 @@ public class OvsdbDao extends OvsdbDaoBase {
public void configureBlockList(OvsdbClient ovsdbClient, OpensyncAPConfig opensyncAPConfig,
List<MacAddress> blockList) {
ovsdbSsid.configureBlockList(ovsdbClient, opensyncAPConfig, blockList);
ovsdbSsid.configureBlockList(ovsdbClient, blockList);
}
public void configureCommands(OvsdbClient ovsdbClient, String startdebugengineapcommand,

View File

@@ -122,19 +122,13 @@ public class OvsdbNetworkConfig extends OvsdbDaoBase {
* @param isNat
*/
void configureInetInterface(OvsdbClient ovsdbClient, String ifName, boolean enabled, String ifType,
boolean isUpdate, boolean isNat) {
try {
List<Operation> operations = new ArrayList<>();
boolean isUpdate, boolean isNat, List<Operation> operations) {
Map<String, Value> 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("NAT", new Atom<>(isNat));
Row row = new Row(tableColumns);
if (isUpdate) {
List<Condition> conditions = new ArrayList<>();
@@ -143,50 +137,24 @@ public class OvsdbNetworkConfig extends OvsdbDaoBase {
} else {
operations.add(new Insert(wifiInetConfigDbTable, row));
}
CompletableFuture<OperationResult[]> fResult = ovsdbClient.transact(ovsdbName, operations);
OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS);
LOG.debug("Updated Inet {}", ifName);
for (OperationResult res : result) {
if (res instanceof InsertResult) {
LOG.info("configureInetInterface insert new row result {}", (res));
// for insert, make sure it is actually in the table
confirmRowExistsInTable(ovsdbClient, ((InsertResult) res).getUuid(), wifiInetConfigDbTable);
} else if (res instanceof UpdateResult) {
LOG.info("configureInetInterface update new row result {}", (res));
} else if (res instanceof ErrorResult) {
LOG.error("configureInetInterface error {}", (res));
throw new RuntimeException("configureInetInterface " + ((ErrorResult) res).getError() + " "
+ ((ErrorResult) res).getDetails());
}
}
} catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) {
LOG.error("Error in updateWifiInetConfig", e);
throw new RuntimeException(e);
}
}
/**
*
* @param ovsdbClient
* @param ovsdbClient
* @param vifInterfaceName
* @param enabled
* @param networkForwardMode
* @param operations
*/
void configureInetVifInterface(OvsdbClient ovsdbClient, String vifInterfaceName, boolean enabled,
NetworkForwardMode networkForwardMode) {
NetworkForwardMode networkForwardMode, List<Operation> operations) {
Map<String, WifiInetConfigInfo> inetConfigs = ovsdbGet.getProvisionedWifiInetConfigs(ovsdbClient);
if (inetConfigs.containsKey(vifInterfaceName)) {
configureInetInterface(ovsdbClient, vifInterfaceName, enabled, "vif", true,
(networkForwardMode == NetworkForwardMode.NAT));
(networkForwardMode == NetworkForwardMode.NAT), operations);
} else {
configureInetInterface(ovsdbClient, vifInterfaceName, enabled, "vif", false,
(networkForwardMode == NetworkForwardMode.NAT));
(networkForwardMode == NetworkForwardMode.NAT), operations);
}
}

View File

@@ -1,48 +1,37 @@
package com.telecominfraproject.wlan.opensync.ovsdb.dao;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.telecominfraproject.wlan.core.model.equipment.ChannelBandwidth;
import com.telecominfraproject.wlan.core.model.equipment.RadioType;
import com.telecominfraproject.wlan.core.model.equipment.SourceType;
import com.telecominfraproject.wlan.equipment.models.*;
import com.telecominfraproject.wlan.opensync.external.integration.models.OpensyncAPConfig;
import com.telecominfraproject.wlan.opensync.ovsdb.dao.models.WifiRadioConfigInfo;
import com.telecominfraproject.wlan.opensync.ovsdb.dao.models.WifiVifConfigInfo;
import com.telecominfraproject.wlan.profile.rf.models.RfConfiguration;
import com.telecominfraproject.wlan.profile.rf.models.RfElementConfiguration;
import com.vmware.ovsdb.exception.OvsdbClientException;
import com.vmware.ovsdb.protocol.operation.Operation;
import com.vmware.ovsdb.protocol.operation.Update;
import com.vmware.ovsdb.protocol.operation.notation.*;
import com.vmware.ovsdb.protocol.operation.result.OperationResult;
import com.vmware.ovsdb.service.OvsdbClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.springframework.stereotype.Component;
import com.telecominfraproject.wlan.core.model.equipment.ChannelBandwidth;
import com.telecominfraproject.wlan.core.model.equipment.RadioType;
import com.telecominfraproject.wlan.core.model.equipment.SourceType;
import com.telecominfraproject.wlan.equipment.models.ApElementConfiguration;
import com.telecominfraproject.wlan.equipment.models.ElementRadioConfiguration;
import com.telecominfraproject.wlan.equipment.models.MimoMode;
import com.telecominfraproject.wlan.equipment.models.RadioConfiguration;
import com.telecominfraproject.wlan.equipment.models.StateSetting;
import com.telecominfraproject.wlan.opensync.external.integration.models.OpensyncAPConfig;
import com.telecominfraproject.wlan.profile.rf.models.RfConfiguration;
import com.telecominfraproject.wlan.profile.rf.models.RfElementConfiguration;
import com.vmware.ovsdb.exception.OvsdbClientException;
import com.vmware.ovsdb.protocol.operation.Mutate;
import com.vmware.ovsdb.protocol.operation.Operation;
import com.vmware.ovsdb.protocol.operation.Select;
import com.vmware.ovsdb.protocol.operation.Update;
import com.vmware.ovsdb.protocol.operation.notation.Atom;
import com.vmware.ovsdb.protocol.operation.notation.Condition;
import com.vmware.ovsdb.protocol.operation.notation.Function;
import com.vmware.ovsdb.protocol.operation.notation.Mutation;
import com.vmware.ovsdb.protocol.operation.notation.Mutator;
import com.vmware.ovsdb.protocol.operation.notation.Row;
import com.vmware.ovsdb.protocol.operation.notation.Uuid;
import com.vmware.ovsdb.protocol.operation.notation.Value;
import com.vmware.ovsdb.protocol.operation.result.ErrorResult;
import com.vmware.ovsdb.protocol.operation.result.OperationResult;
import com.vmware.ovsdb.protocol.operation.result.SelectResult;
import com.vmware.ovsdb.protocol.operation.result.UpdateResult;
import com.vmware.ovsdb.service.OvsdbClient;
@Component
public class OvsdbRadioConfig extends OvsdbDaoBase {
@Autowired
OvsdbGet ovsdbGet;
void configureWifiRadios(OvsdbClient ovsdbClient, OpensyncAPConfig opensyncAPConfig) {
String country = opensyncAPConfig.getCountryCode(); // should be the
@@ -54,6 +43,11 @@ public class OvsdbRadioConfig extends OvsdbDaoBase {
.getDetails();
RfConfiguration rfConfig = (RfConfiguration) opensyncAPConfig.getRfProfile().getDetails();
Map<String, WifiRadioConfigInfo> provisionedRadioConfigs = ovsdbGet.getProvisionedWifiRadioConfigs(ovsdbClient);
Map<String, WifiVifConfigInfo> vifConfigs = ovsdbGet.getProvisionedWifiVifConfigs(ovsdbClient);
List<Operation> operations = new ArrayList<>();
for (RadioType radioType : apElementConfiguration.getRadioMap().keySet()) {
Map<String, String> hwConfig = new HashMap<>();
@@ -64,7 +58,7 @@ public class OvsdbRadioConfig extends OvsdbDaoBase {
LOG.debug("configureWifiRadios autoChannelSelection {} activeChannel {} getChannelNumber {} ",
autoChannelSelection, channel, elementRadioConfig.getChannelNumber());
ChannelBandwidth bandwidth = rfElementConfig.getChannelBandwidth();
String ht_mode = null;
String ht_mode;
switch (bandwidth) {
case is20MHz:
ht_mode = "HT20";
@@ -89,7 +83,7 @@ public class OvsdbRadioConfig extends OvsdbDaoBase {
int beaconInterval = rfElementConfig.getBeaconInterval();
boolean enabled = radioConfig.getRadioAdminState().equals(StateSetting.enabled);
int txPower = 0;
int txPower;
if (elementRadioConfig.getEirpTxPower().getSource() == SourceType.profile) {
txPower = rfElementConfig.getEirpTxPower();
} else {
@@ -121,7 +115,7 @@ public class OvsdbRadioConfig extends OvsdbDaoBase {
break;
default:
}
String freqBand = null;
String freqBand;
switch (radioType) {
case is2dot4GHz:
freqBand = "2.4G";
@@ -170,44 +164,77 @@ public class OvsdbRadioConfig extends OvsdbDaoBase {
}
String radioName = null;
for (String key : provisionedRadioConfigs.keySet()) {
if (provisionedRadioConfigs.get(key).freqBand.equals(freqBand)) {
radioName = key;
break;
}
}
if (radioName == null) continue;
String ifName = null; // for vifConfigs
if (radioName.equals(radio0)) {
ifName = defaultRadio0;
} else if (radioName.equals(radio1)) {
ifName = defaultRadio1;
} else if (radioName.equals(radio2)) {
ifName = defaultRadio2;
}
if (ifName == null) continue;
Set<Uuid> vifUuidsForRadio = new HashSet<>();
for (String key : vifConfigs.keySet()) {
if (key.contains(ifName))
vifUuidsForRadio.add(vifConfigs.get(key).uuid);
}
int mimoMode = MimoMode.none.getId();
if (rfElementConfig.getMimoMode() != null) {
mimoMode = rfElementConfig.getMimoMode().getId();
}
if (freqBand != null) {
try {
configureWifiRadios(ovsdbClient, freqBand, channel, hwConfig, country.toUpperCase(), beaconInterval,
enabled, hwMode, ht_mode, txPower, mimoMode);
} catch (OvsdbClientException e) {
LOG.error("ConfigureWifiRadios failed with OvsdbClient exception.", e);
throw new RuntimeException(e);
try {
} catch (TimeoutException e) {
LOG.error("ConfigureWifiRadios failed with Timeout.", e);
throw new RuntimeException(e);
configureWifiRadios(freqBand, channel, hwConfig, country.toUpperCase(), beaconInterval,
enabled, hwMode, ht_mode, txPower, mimoMode, vifUuidsForRadio, operations);
} catch (OvsdbClientException e) {
LOG.error("ConfigureWifiRadios failed with OvsdbClient exception.", e);
throw new RuntimeException(e);
} catch (ExecutionException e) {
LOG.error("ConfigureWifiRadios excecution failed.", e);
throw new RuntimeException(e);
} catch (TimeoutException e) {
LOG.error("ConfigureWifiRadios failed with Timeout.", e);
throw new RuntimeException(e);
} catch (InterruptedException e) {
LOG.error("ConfigureWifiRadios interrupted.", e);
throw new RuntimeException(e);
} catch (ExecutionException e) {
LOG.error("ConfigureWifiRadios excecution failed.", e);
throw new RuntimeException(e);
}
} catch (InterruptedException e) {
LOG.error("ConfigureWifiRadios interrupted.", e);
throw new RuntimeException(e);
}
}
try {
CompletableFuture<OperationResult[]> fResult = ovsdbClient.transact(ovsdbName, operations);
OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS);
for (OperationResult res : result) {
LOG.debug("Op Result {}", res);
}
} catch (OvsdbClientException | ExecutionException | InterruptedException | TimeoutException e) {
LOG.error("configureWifiRadios error", e); throw new RuntimeException(e);
}
}
void configureWifiRadios(OvsdbClient ovsdbClient, String freqBand, int channel, Map<String, String> hwConfig,
String country, int beaconInterval, boolean enabled, String hwMode, String ht_mode, int txPower,
int mimoMode) throws OvsdbClientException, TimeoutException, ExecutionException, InterruptedException {
void configureWifiRadios(String freqBand, int channel, Map<String, String> hwConfig,
String country, int beaconInterval, boolean enabled, String hwMode, String ht_mode, int txPower,
int mimoMode, Set<Uuid> vifUuidsForRadio, List<Operation> operations) throws OvsdbClientException, TimeoutException, ExecutionException, InterruptedException {
List<Operation> operations = new ArrayList<>();
Map<String, Value> updateColumns = new HashMap<>();
List<Condition> conditions = new ArrayList<>();
conditions.add(new Condition("freq_band", Function.EQUALS, new Atom<>(freqBand)));
@@ -234,23 +261,20 @@ public class OvsdbRadioConfig extends OvsdbDaoBase {
updateColumns.put("hw_mode", new Atom<>(hwMode));
}
setTxAndRxChainmask(ovsdbClient, mimoMode, updateColumns);
setTxAndRxChainmask(mimoMode, updateColumns);
if (vifUuidsForRadio.size() > 0) {
com.vmware.ovsdb.protocol.operation.notation.Set vifConfigUuids = com.vmware.ovsdb.protocol.operation.notation.Set
.of(vifUuidsForRadio);
updateColumns.put("vif_configs", vifConfigUuids);
}
Row row = new Row(updateColumns);
operations.add(new Update(wifiRadioConfigDbTable, conditions, row));
CompletableFuture<OperationResult[]> fResult = ovsdbClient.transact(ovsdbName, operations);
OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS);
LOG.debug("Provisioned channel {} for {}", channel, freqBand);
for (OperationResult res : result) {
LOG.debug("Op Result {}", res);
}
}
void setTxAndRxChainmask(OvsdbClient ovsdbClient, int mimoMode, Map<String, Value> updateColumns)
throws InterruptedException, ExecutionException, OvsdbClientException {
void setTxAndRxChainmask(int mimoMode, Map<String, Value> updateColumns) {
/*
* Chainmask is a bitmask, so map mimo mode values accordingly
* Note values 0, 1 remain unchanged
@@ -270,65 +294,4 @@ public class OvsdbRadioConfig extends OvsdbDaoBase {
}
/**
* Update the vif_configs column of the Wifi_Radio_Config ovsdb table for
* the given freqBand
*
* @param ovsdbClient
* @param ssid
* @param radioFreqBand
* @param vifConfigUuid
* @throws OvsdbClientException
* @throws InterruptedException
* @throws ExecutionException
* @throws TimeoutException
*/
void updateVifConfigsSetForRadio(OvsdbClient ovsdbClient, String ssid, String radioFreqBand, Uuid vifConfigUuid)
throws OvsdbClientException, InterruptedException, ExecutionException, TimeoutException {
List<Operation> operations = new ArrayList<>();
List<Condition> conditions = new ArrayList<>();
conditions.add(new Condition("freq_band", Function.EQUALS, new Atom<>(radioFreqBand)));
List<Mutation> mutations = new ArrayList<>();
Mutation mutation = new Mutation("vif_configs", Mutator.INSERT, new Atom<>(vifConfigUuid));
mutations.add(mutation);
operations.add(new Mutate(wifiRadioConfigDbTable, conditions, mutations));
CompletableFuture<OperationResult[]> fResult = ovsdbClient.transact(ovsdbName, operations);
OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS);
for (OperationResult res : result) {
if (res instanceof UpdateResult) {
LOG.debug("updateVifConfigsSetForRadio:result {}", res);
} else if (res instanceof ErrorResult) {
LOG.error("updateVifConfigsSetForRadio error {}", (res));
throw new RuntimeException("updateVifConfigsSetForRadio " + ((ErrorResult) res).getError() + " "
+ ((ErrorResult) res).getDetails());
}
}
// confirm the table was updated with the new Wifi_VIF_Config Uuid
operations.clear();
operations.add(new Select(wifiRadioConfigDbTable, conditions));
fResult = ovsdbClient.transact(ovsdbName, operations);
result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS);
for (OperationResult res : result) {
if (res instanceof SelectResult) {
SelectResult selectResult = (SelectResult) res;
Row row = selectResult.getRows().get(0);
if (!row.getSetColumn("vif_configs").contains(vifConfigUuid)) {
throw new RuntimeException("Wifi_Radio_Config " + row
+ "vif_configs table was not updated {} for new Wifi_VIF_Config " + vifConfigUuid);
}
} else if (res instanceof ErrorResult) {
LOG.error("updateVifConfigsSetForRadio error {}", (res));
throw new RuntimeException("updateVifConfigsSetForRadio " + ((ErrorResult) res).getError() + " "
+ ((ErrorResult) res).getDetails());
}
}
LOG.info("Updated WifiRadioConfig {} for SSID {}:", radioFreqBand, ssid);
}
}

View File

@@ -1,31 +1,8 @@
package com.telecominfraproject.wlan.opensync.ovsdb.dao;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.telecominfraproject.wlan.core.model.equipment.MacAddress;
import com.telecominfraproject.wlan.core.model.equipment.RadioType;
import com.telecominfraproject.wlan.equipment.models.ApElementConfiguration;
import com.telecominfraproject.wlan.equipment.models.NetworkForwardMode;
import com.telecominfraproject.wlan.equipment.models.RadioConfiguration;
import com.telecominfraproject.wlan.equipment.models.RadioMode;
import com.telecominfraproject.wlan.equipment.models.StateSetting;
import com.telecominfraproject.wlan.equipment.models.*;
import com.telecominfraproject.wlan.opensync.external.integration.models.ConnectNodeInfo;
import com.telecominfraproject.wlan.opensync.external.integration.models.OpensyncAPConfig;
import com.telecominfraproject.wlan.opensync.ovsdb.dao.models.WifiRadioConfigInfo;
@@ -46,23 +23,22 @@ import com.telecominfraproject.wlan.profile.ssid.models.NasIdType;
import com.telecominfraproject.wlan.profile.ssid.models.NasIpType;
import com.telecominfraproject.wlan.profile.ssid.models.SsidConfiguration;
import com.vmware.ovsdb.exception.OvsdbClientException;
import com.vmware.ovsdb.protocol.operation.Delete;
import com.vmware.ovsdb.protocol.operation.Insert;
import com.vmware.ovsdb.protocol.operation.Operation;
import com.vmware.ovsdb.protocol.operation.Select;
import com.vmware.ovsdb.protocol.operation.Update;
import com.vmware.ovsdb.protocol.operation.notation.Atom;
import com.vmware.ovsdb.protocol.operation.notation.Condition;
import com.vmware.ovsdb.protocol.operation.notation.Function;
import com.vmware.ovsdb.protocol.operation.notation.Row;
import com.vmware.ovsdb.protocol.operation.notation.Uuid;
import com.vmware.ovsdb.protocol.operation.notation.Value;
import com.vmware.ovsdb.protocol.operation.result.ErrorResult;
import com.vmware.ovsdb.protocol.operation.result.InsertResult;
import com.vmware.ovsdb.protocol.operation.result.OperationResult;
import com.vmware.ovsdb.protocol.operation.result.SelectResult;
import com.vmware.ovsdb.protocol.operation.result.UpdateResult;
import com.vmware.ovsdb.protocol.operation.*;
import com.vmware.ovsdb.protocol.operation.notation.*;
import com.vmware.ovsdb.protocol.operation.result.*;
import com.vmware.ovsdb.service.OvsdbClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.*;
import java.util.Set;
import java.util.Map.Entry;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;
@Component
public class OvsdbSsidConfig extends OvsdbDaoBase {
@@ -70,8 +46,6 @@ public class OvsdbSsidConfig extends OvsdbDaoBase {
@Autowired
OvsdbGet getProvisionedData;
@Autowired
OvsdbRadioConfig radioConfig;
@Autowired
OvsdbNetworkConfig networkConfig;
@Autowired
OvsdbNode ovsdbNode;
@@ -132,7 +106,7 @@ public class OvsdbSsidConfig extends OvsdbDaoBase {
}
void configureBlockList(OvsdbClient ovsdbClient, OpensyncAPConfig opensyncApConfig, List<MacAddress> macBlockList) {
void configureBlockList(OvsdbClient ovsdbClient, List<MacAddress> macBlockList) {
LOG.debug("Starting configureBlockList {}", macBlockList);
@@ -170,18 +144,11 @@ public class OvsdbSsidConfig extends OvsdbDaoBase {
*
* @param enable80211k
* @param dtimPeriod
* @param fragThresholdBytes
* @param customOptions
*/
void configureCustomOptionsForDtimFragAnd80211k(boolean enable80211k, int dtimPeriod, int fragThresholdBytes,
Map<String, String> customOptions) {
// TODO: the frag_threshold is not supported on the AP
// customOptions.put("frag_threshold",
// String.valueOf(fragThresholdBytes));
void configureCustomOptionsForDtimFragAnd80211k(boolean enable80211k, int dtimPeriod,
Map<String, String> customOptions) {
customOptions.put("dtim_period", String.valueOf(dtimPeriod));
if (enable80211k) {
customOptions.put("ieee80211k", String.valueOf(1));
} else {
@@ -254,7 +221,6 @@ public class OvsdbSsidConfig extends OvsdbDaoBase {
* @param clientDlLimit
* @param clientUlLimit
* @param rtsCtsThreshold
* @param fragThresholdBytes
* @param dtimPeriod
* @param radiusNasId
* @param radiusNasIp
@@ -263,16 +229,16 @@ public class OvsdbSsidConfig extends OvsdbDaoBase {
* @param dynamicVlan
*/
void configureCustomOptionsForSsid(OvsdbClient ovsdbClient, boolean enable80211k, boolean rateLimitEnable,
int ssidDlLimit, int ssidUlLimit, int clientDlLimit, int clientUlLimit, int rtsCtsThreshold,
int fragThresholdBytes, int dtimPeriod, String radiusNasId, String radiusNasIp, String radiusOperatorName,
Map<String, Value> updateColumns, int dynamicVlan) {
int ssidDlLimit, int ssidUlLimit, int clientDlLimit, int clientUlLimit, int rtsCtsThreshold,
int dtimPeriod, String radiusNasId, String radiusNasIp, String radiusOperatorName,
Map<String, Value> updateColumns, int dynamicVlan) {
Map<String, String> customOptions = new HashMap<>();
configureCustomOptionsForRatesAndLimits(rateLimitEnable, ssidDlLimit, ssidUlLimit, clientDlLimit, clientUlLimit,
rtsCtsThreshold, customOptions);
configureCustomOptionsForRadiusNas(ovsdbClient, radiusNasId, radiusNasIp, radiusOperatorName, customOptions);
configureCustomOptionsForDtimFragAnd80211k(enable80211k, dtimPeriod, fragThresholdBytes, customOptions);
configureCustomOptionsForDtimFragAnd80211k(enable80211k, dtimPeriod, customOptions);
configureCustomOptionsForDynamicVlan(dynamicVlan, customOptions);
@@ -282,26 +248,22 @@ public class OvsdbSsidConfig extends OvsdbDaoBase {
updateColumns.put("custom_options", customMap);
}
Uuid configureSingleSsid(OvsdbClient ovsdbClient, String vifInterfaceName, String ssid, boolean ssidBroadcast,
Map<String, String> 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<String, String> dns, String ipAssignScheme, List<MacAddress> macBlockList,
boolean rateLimitEnable, int ssidDlLimit, int ssidUlLimit, int clientDlLimit, int clientUlLimit,
int rtsCtsThreshold, int fragThresholdBytes, int dtimPeriod, Map<String, String> captiveMap,
List<String> walledGardenAllowlist, Map<Short, Set<String>> bonjourServiceMap, String radiusNasId,
String radiusNasIp, String radiusOperatorName, String greTunnelName, int dynamicVlan) {
void configureSingleSsid(OvsdbClient ovsdbClient, String vifInterfaceName, String ssid, boolean ssidBroadcast,
Map<String, String> security, int vlanId, boolean rrmEnabled, boolean enable80211r,
int mobilityDomain, boolean enable80211v, boolean enable80211k, String minHwMode, boolean enabled,
int keyRefresh, boolean uapsdEnabled, boolean apBridge, NetworkForwardMode networkForwardMode,
List<MacAddress> macBlockList,
boolean rateLimitEnable, int ssidDlLimit, int ssidUlLimit, int clientDlLimit, int clientUlLimit,
int rtsCtsThreshold, int dtimPeriod, Map<String, String> captiveMap,
List<String> walledGardenAllowlist, String radiusNasId,
String radiusNasIp, String radiusOperatorName, String greTunnelName, int dynamicVlan, List<Operation> operations) {
List<Operation> operations = new ArrayList<>();
Map<String, Value> updateColumns = new HashMap<>();
try {
// If we are doing a NAT SSID, no bridge, else yes
// If gre tunnel and vlanId > 1 use vlan if name for bridge
String bridgeInterfaceName = defaultWanInterfaceName;
if (greTunnelName != null && vlanId > 1) {
bridgeInterfaceName = greTunnelName + "_" + String.valueOf(vlanId);
bridgeInterfaceName = greTunnelName + "_" + vlanId;
} else if (networkForwardMode == NetworkForwardMode.NAT) {
bridgeInterfaceName = defaultLanInterfaceName;
}
@@ -320,21 +282,14 @@ public class OvsdbSsidConfig extends OvsdbDaoBase {
if (walledGardenAllowlist != null && !walledGardenAllowlist.isEmpty()) {
Set<Atom<String>> atomMacList = new HashSet<>();
walledGardenAllowlist.stream().forEach(allow -> atomMacList.add(new Atom<>(allow)));
walledGardenAllowlist.forEach(allow -> atomMacList.add(new Atom<>(allow)));
com.vmware.ovsdb.protocol.operation.notation.Set allowListSet = com.vmware.ovsdb.protocol.operation.notation.Set
.of(atomMacList);
updateColumns.put("captive_allowlist", allowListSet);
} else {
updateColumns.put("captive_allowlist", new com.vmware.ovsdb.protocol.operation.notation.Set());
}
// TODO: when AP support for Bonjour Gateway set values
if (bonjourServiceMap != null && bonjourServiceMap.size() > 0) {
LOG.info("SSID {} Bonjour Services per vlan {}", ssid, bonjourServiceMap);
}
updateColumns.put("bridge", new Atom<>(bridgeInterfaceName));
if (enable80211v) {
updateColumns.put("btm", new Atom<>(1));
} else {
@@ -353,59 +308,19 @@ public class OvsdbSsidConfig extends OvsdbDaoBase {
updateColumns.put("ssid", new Atom<>(ssid));
updateColumns.put("ssid_broadcast", new Atom<>(ssidBroadcast ? "enabled" : "disabled"));
updateColumns.put("uapsd_enable", new Atom<>(uapsdEnabled));
updateColumns.put("min_hw_mode", new Atom<>(minHwMode));
updateColumns.put("group_rekey", new Atom<>(keyRefresh));
updateColumns.put("uapsd_enable", new Atom<>(uapsdEnabled));
updateColumns.put("ap_bridge", new Atom<>(apBridge));
@SuppressWarnings("unchecked")
com.vmware.ovsdb.protocol.operation.notation.Map<String, String> securityMap = com.vmware.ovsdb.protocol.operation.notation.Map
.of(security);
updateColumns.put("security", securityMap);
configureCustomOptionsForSsid(ovsdbClient, enable80211k, rateLimitEnable, ssidDlLimit, ssidUlLimit,
clientDlLimit, clientUlLimit, rtsCtsThreshold, fragThresholdBytes, dtimPeriod, radiusNasId,
clientDlLimit, clientUlLimit, rtsCtsThreshold, dtimPeriod, radiusNasId,
radiusNasIp, radiusOperatorName, updateColumns, dynamicVlan);
updateBlockList(updateColumns, macBlockList);
Row row = new Row(updateColumns);
operations.add(new Insert(wifiVifConfigDbTable, row));
CompletableFuture<OperationResult[]> fResult = ovsdbClient.transact(ovsdbName, operations);
OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS);
Uuid vifConfigUuid = null;
for (OperationResult res : result) {
InsertResult insertResult = null;
if (res instanceof InsertResult) {
insertResult = (InsertResult) res;
LOG.info("configureSingleSsid:InsertResult {}", insertResult);
vifConfigUuid = ((InsertResult) res).getUuid();
} else if (res instanceof ErrorResult) {
LOG.error("configureSingleSsid: error {}", (res));
throw new RuntimeException("configureSingleSsid " + ((ErrorResult) res).getError() + " "
+ ((ErrorResult) res).getDetails());
}
}
if (vifConfigUuid == null) {
throw new IllegalStateException("Wifi_VIF_Config entry was not created successfully");
}
confirmRowExistsInTable(ovsdbClient, vifConfigUuid, wifiVifConfigDbTable);
LOG.info("configureSingleSsid:Provisioned SSID {} on interface {} / {}", ssid, vifInterfaceName,
radioFreqBand);
return vifConfigUuid;
} catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) {
LOG.error("Error in configureSingleSsid", e);
throw new RuntimeException(e);
}
}
void configureSsids(OvsdbClient ovsdbClient, OpensyncAPConfig opensyncApConfig) {
@@ -420,7 +335,8 @@ public class OvsdbSsidConfig extends OvsdbDaoBase {
List<RadioType> enabledRadiosFromAp = new ArrayList<>();
getEnabledRadios(ovsdbClient, enabledRadiosFromAp);
Map<String, Integer> interfacesPerFreqBand = new HashMap<>();
List<Operation> operations = new ArrayList<>();
for (Profile ssidProfile : opensyncApConfig.getSsidProfile()) {
SsidConfiguration ssidConfig = (SsidConfiguration) ssidProfile.getDetails();
@@ -482,8 +398,8 @@ public class OvsdbSsidConfig extends OvsdbDaoBase {
break;
}
}
if ((radioName == null) || (freqBand == null)) {
LOG.debug("Cannot provision SSID with radio if_name {} and freqBand {}", radioName, freqBand);
if (radioName == null) {
LOG.debug("Cannot provision SSID with radio if_name null and freqBand {}", freqBand);
continue;
}
if (radioName.equals(radio0)) {
@@ -494,8 +410,7 @@ public class OvsdbSsidConfig extends OvsdbDaoBase {
ifName = defaultRadio2;
}
if (ifName == null) {
LOG.debug("Cannot provision SSID for radio {} freqBand {} with VIF if_name {}", radioName, freqBand,
ifName);
LOG.debug("Cannot provision SSID for radio {} freqBand {} with VIF if_name null", radioName, freqBand);
continue;
}
@@ -503,43 +418,18 @@ public class OvsdbSsidConfig extends OvsdbDaoBase {
boolean ssidBroadcast = ssidConfig.getBroadcastSsid() == StateSetting.enabled;
String ipAssignScheme = apElementConfig.getGettingIP().toString();
// the following 5 attributes only applicable to static
// ipAssignScheme,
// else they are
// ignored
String gateway = null;
String inet = null;
Map<String, String> dns = null;
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";
}
}
RfElementConfiguration rfElementConfig = rfConfig.getRfConfig(radioType);
int rtsCtsThreshold = rfElementConfig.getRtsCtsThreshold();
RadioMode radioMode = rfElementConfig.getRadioMode();
int dtimPeriod = 2;
int fragThresholdBytes = 2346;
boolean uapsdEnabled = true;
boolean apBridge = true;
RadioConfiguration radioConfiguration = apElementConfig.getAdvancedRadioMap().get(radioType);
int dtimPeriod = 2;
if (radioConfiguration != null) {
dtimPeriod = radioConfiguration.getDtimPeriod();
uapsdEnabled = radioConfiguration.getUapsdState() == StateSetting.enabled;
apBridge = radioConfiguration.getStationIsolation() == StateSetting.disabled; // stationIsolation
fragThresholdBytes = radioConfiguration.getFragmentationThresholdBytes();
}
String minHwMode = "11n"; // min_hw_mode is 11n
@@ -634,46 +524,44 @@ public class OvsdbSsidConfig extends OvsdbDaoBase {
int vlanId = ssidConfig.getVlanId() != null ? ssidConfig.getVlanId() : 1;
Optional<GreTunnelConfiguration> tunnelConfiguration = ((ApNetworkConfiguration) opensyncApConfig
.getApProfile().getDetails()).getGreTunnelConfigurations().stream()
.filter(new Predicate<GreTunnelConfiguration>() {
@Override
public boolean test(GreTunnelConfiguration t) {
return t.getVlanIdsInGreTunnel().contains(vlanId);
}
}).findFirst();
.filter(t -> t.getVlanIdsInGreTunnel().contains(vlanId)).findFirst();
String greTunnelName = null;
if (tunnelConfiguration.isPresent()) {
greTunnelName = tunnelConfiguration.get().getGreTunnelName();
}
if (interfacesPerFreqBand.containsKey(freqBand)) {
Integer numIf = interfacesPerFreqBand.get(freqBand);
ifName = ifName + "_" + numIf.toString();
interfacesPerFreqBand.put(freqBand, ++numIf);
} else {
interfacesPerFreqBand.put(freqBand, 1);
}
try {
ifName = getInterfaceNameForVifConfig(ovsdbClient, opensyncApConfig, ssidConfig, freqBand, ifName);
String greTunnelName = null;
if (tunnelConfiguration.isPresent()) {
greTunnelName = tunnelConfiguration.get().getGreTunnelName();
}
Uuid vifConfigUuid = configureSingleSsid(ovsdbClient, ifName, ssidConfig.getSsid(), ssidBroadcast,
security, freqBand, vlanId, rrmEnabled, enable80211r, mobilityDomain, enable80211v,
configureSingleSsid(ovsdbClient, ifName, ssidConfig.getSsid(), ssidBroadcast,
security, vlanId, rrmEnabled, enable80211r, mobilityDomain, enable80211v,
enable80211k, minHwMode, enabled, keyRefresh, uapsdEnabled, apBridge,
ssidConfig.getForwardMode(), gateway, inet, dns, ipAssignScheme, macBlockList,
ssidConfig.getForwardMode(), macBlockList,
rateLimitEnable, ssidDlLimit, ssidUlLimit, clientDlLimit, clientUlLimit, rtsCtsThreshold,
fragThresholdBytes, dtimPeriod, captiveMap, walledGardenAllowlist, bonjourServiceMap,
radiusNasId, radiusNasIp, radiusOperName, greTunnelName, dynamicVlan);
dtimPeriod, captiveMap, walledGardenAllowlist,
radiusNasId, radiusNasIp, radiusOperName, greTunnelName, dynamicVlan,operations);
radioConfig.updateVifConfigsSetForRadio(ovsdbClient, ssidConfig.getSsid(), freqBand, vifConfigUuid);
networkConfig.configureInetVifInterface(ovsdbClient, ifName, enabled, ssidConfig.getForwardMode());
} catch (IllegalStateException | OvsdbClientException | InterruptedException | ExecutionException
| TimeoutException e) {
networkConfig.configureInetVifInterface(ovsdbClient, ifName, enabled, ssidConfig.getForwardMode(),operations );
} catch (IllegalStateException e) {
// could not provision this SSID, but still can go on
LOG.warn("could not provision SSID {} on {}", ssidConfig.getSsid(), freqBand);
}
}
}
try {
CompletableFuture<OperationResult[]> fResult = ovsdbClient.transact(ovsdbName, operations);
OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS);
LOG.debug("configureSsids result {}", Arrays.toString(result));
} catch (OvsdbClientException | InterruptedException | ExecutionException | TimeoutException e) {
LOG.error("Unable to configureSsids on AP.", e);
throw new RuntimeException(e);
}
}
void getBonjourGatewayConfiguration(OpensyncAPConfig opensyncApConfig, SsidConfiguration ssidConfig,
@@ -689,7 +577,7 @@ public class OvsdbSsidConfig extends OvsdbDaoBase {
Collection<BonjourServiceSet> bonjourServicesCollection = bonjourGatewayConfiguration
.getBonjourServices();
bonjourServicesCollection.stream().forEach(b -> {
bonjourServicesCollection.forEach(b -> {
Set<String> serviceSet = new HashSet<>();
if (bonjourServiceMap.containsKey(b.getVlanId())) {
serviceSet.addAll(bonjourServiceMap.get(b.getVlanId()));
@@ -749,7 +637,7 @@ public class OvsdbSsidConfig extends OvsdbDaoBase {
if (captiveProfileDetails.getAuthenticationType().equals(CaptivePortalAuthenticationType.radius)) {
Optional<Profile> optional = opensyncApConfig.getRadiusProfiles().stream()
.filter(p -> p.getId() == captiveProfileDetails.getRadiusServiceId()).findFirst();
if (optional != null && optional.isPresent()) {
if (optional.isPresent()) {
Profile profile = optional.get();
RadiusProfile radiusProfile = (RadiusProfile) profile.getDetails();
captiveMap.put("radius_server_ip", String.valueOf(
@@ -805,46 +693,6 @@ public class OvsdbSsidConfig extends OvsdbDaoBase {
}
}
/**
* Get the interface name for the new Wifi_VIF_Config. Maximum of 8
* interface names per frequencyBand
*
* @param ovsdbClient
* @param opensyncApConfig
* @param ssidConfig
* @param freqBand
* @param ifName
* @return the interface name, i.e. wlan0, wlan0_1, etc
*/
String getInterfaceNameForVifConfig(OvsdbClient ovsdbClient, OpensyncAPConfig opensyncApConfig,
SsidConfiguration ssidConfig, String freqBand, String ifName) {
Map<String, WifiVifConfigInfo> provisionedVifs = getProvisionedData.getProvisionedWifiVifConfigs(ovsdbClient);
List<String> interfaces = new ArrayList<>();
interfaces.add(ifName);
for (int i = 1; i < MAX_VIF_PER_FREQ; i++) {
interfaces.add(ifName + "_" + Integer.toString(i));
}
for (String key : provisionedVifs.keySet()) {
if (key.contains(ifName)) {
String provisionedIfName = provisionedVifs.get(key).ifName;
if (interfaces.remove(provisionedIfName)) {
LOG.info("Interface {} already in use on Radio {}, cannot be used for new Wifi_VIF_Config.",
provisionedIfName, freqBand);
}
}
}
if (interfaces.isEmpty()) {
throw new RuntimeException("No more available interfaces on AP "
+ opensyncApConfig.getCustomerEquipment().getName() + " for frequency band " + freqBand);
} else {
// take the first available interface for this band
ifName = interfaces.get(0);
LOG.info("Configuring new Wifi_VIF_Config for ssid {} with if_name {}", ssidConfig.getSsid(), ifName);
}
return ifName;
}
/**
* Maps between the osvdb security definitions and the cloud's security mode
* for the give SSID being configured.
@@ -854,21 +702,31 @@ public class OvsdbSsidConfig extends OvsdbDaoBase {
* @return
*/
String getOpensyncSecurityMode(String ssidSecurityMode, String opensyncSecurityMode) {
if (ssidSecurityMode.equals("wpaPSK") || ssidSecurityMode.equals("wpa2PSK")
|| ssidSecurityMode.equals("wpa2OnlyPSK")) {
opensyncSecurityMode = "WPA-PSK";
} else if (ssidSecurityMode.equals("wep")) {
opensyncSecurityMode = "WEP";
} else if (ssidSecurityMode.equals("wpaEAP") || ssidSecurityMode.equals("wpa2EAP")
|| ssidSecurityMode.equals("wpa2OnlyEAP")) {
opensyncSecurityMode = "WPA-EAP";
} else if (ssidSecurityMode.equals("wpaRadius") || ssidSecurityMode.equals("wpa2OnlyRadius")
|| ssidSecurityMode.equals("wpa2Radius")) {
opensyncSecurityMode = "WPA-EAP";
} else if (ssidSecurityMode.equals("wpa3OnlySAE") || ssidSecurityMode.equals("wpa3MixedSAE")) {
opensyncSecurityMode = "WPA-SAE";
} else if (ssidSecurityMode.equals("wpa3OnlyEAP") || ssidSecurityMode.equals("wpa3MixedEAP")) {
opensyncSecurityMode = "WPA3-EAP";
switch (ssidSecurityMode) {
case "wpaPSK":
case "wpa2PSK":
case "wpa2OnlyPSK":
opensyncSecurityMode = "WPA-PSK";
break;
case "wep":
opensyncSecurityMode = "WEP";
break;
case "wpaEAP":
case "wpa2EAP":
case "wpa2OnlyEAP":
case "wpaRadius":
case "wpa2OnlyRadius":
case "wpa2Radius":
opensyncSecurityMode = "WPA-EAP";
break;
case "wpa3OnlySAE":
case "wpa3MixedSAE":
opensyncSecurityMode = "WPA-SAE";
break;
case "wpa3OnlyEAP":
case "wpa3MixedEAP":
opensyncSecurityMode = "WPA3-EAP";
break;
}
return opensyncSecurityMode;
}
@@ -882,16 +740,9 @@ public class OvsdbSsidConfig extends OvsdbDaoBase {
LOG.debug("Radius Accounting Profiles {}", opensyncApConfig.getRadiusProfiles());
List<Profile> radiusProfileList = opensyncApConfig.getRadiusProfiles().stream()
.filter(new Predicate<Profile>() {
.filter(t -> t.getId() == ssidConfig.getRadiusServiceId()).collect(Collectors.toList());
@Override
public boolean test(Profile t) {
return t.getId() == ssidConfig.getRadiusServiceId();
}
}).collect(Collectors.toList());
if (radiusProfileList != null && radiusProfileList.size() > 0) {
if (radiusProfileList.size() > 0) {
Profile profileRadius = radiusProfileList.get(0);
RadiusProfile profileDetails = ((RadiusProfile) profileRadius.getDetails());
RadiusServer rServer = profileDetails.getPrimaryRadiusAccountingServer();
@@ -907,7 +758,7 @@ public class OvsdbSsidConfig extends OvsdbDaoBase {
} else {
LOG.info("No radius_acct_interval defined for ssid {}, Setting radius_acct_interval to 0",
ssidConfig.getSsid(), rServer);
ssidConfig.getSsid());
security.put("radius_acct_interval", "0");
}
LOG.info(
@@ -934,16 +785,9 @@ public class OvsdbSsidConfig extends OvsdbDaoBase {
LOG.debug("Radius Profiles {}", opensyncApConfig.getRadiusProfiles());
List<Profile> radiusProfileList = opensyncApConfig.getRadiusProfiles().stream()
.filter(new Predicate<Profile>() {
.filter(t -> t.getId() == ssidConfig.getRadiusServiceId()).collect(Collectors.toList());
@Override
public boolean test(Profile t) {
return t.getId() == ssidConfig.getRadiusServiceId();
}
}).collect(Collectors.toList());
if (radiusProfileList != null && radiusProfileList.size() > 0) {
if (radiusProfileList.size() > 0) {
Profile profileRadius = radiusProfileList.get(0);
RadiusProfile profileDetails = ((RadiusProfile) profileRadius.getDetails());
RadiusServer radiusServer = profileDetails.getPrimaryRadiusAuthServer();
@@ -977,41 +821,51 @@ public class OvsdbSsidConfig extends OvsdbDaoBase {
security.put("encryption", opensyncSecurityMode);
// key and mode is N/A for OPEN security
if (!opensyncSecurityMode.equals("OPEN")) {
if (ssidSecurityMode.equals("wpa2PSK") || ssidSecurityMode.equals("wpa3MixedSAE")) {
security.put("key", ssidConfig.getKeyStr());
security.put("mode", "mixed");
} else if (ssidSecurityMode.equals("wpa2OnlyPSK")) {
security.put("key", ssidConfig.getKeyStr());
security.put("mode", "2");
} else if (ssidSecurityMode.equals("wpa3OnlySAE")) {
security.put("key", ssidConfig.getKeyStr());
security.put("mode", "3");
} else if (ssidSecurityMode.equals("wpaPSK")) {
security.put("key", ssidConfig.getKeyStr());
security.put("mode", "1");
} else if (ssidSecurityMode.equals("wpa2OnlyEAP") || ssidSecurityMode.equals("wpa2OnlyRadius")) {
security.put("mode", "2");
getRadiusConfiguration(opensyncApConfig, ssidConfig, security);
getRadiusAccountingConfiguration(opensyncApConfig, ssidConfig, security);
} else if (ssidSecurityMode.equals("wpa3OnlyEAP")) {
security.put("mode", "3");
getRadiusConfiguration(opensyncApConfig, ssidConfig, security);
getRadiusAccountingConfiguration(opensyncApConfig, ssidConfig, security);
switch (ssidSecurityMode) {
case "wpa2PSK":
case "wpa3MixedSAE":
security.put("key", ssidConfig.getKeyStr());
security.put("mode", "mixed");
break;
case "wpa2OnlyPSK":
security.put("key", ssidConfig.getKeyStr());
security.put("mode", "2");
break;
case "wpa3OnlySAE":
security.put("key", ssidConfig.getKeyStr());
security.put("mode", "3");
break;
case "wpaPSK":
case "wep":
security.put("key", ssidConfig.getKeyStr());
security.put("mode", "1");
break;
case "wpa2OnlyEAP":
case "wpa2OnlyRadius":
security.put("mode", "2");
getRadiusConfiguration(opensyncApConfig, ssidConfig, security);
getRadiusAccountingConfiguration(opensyncApConfig, ssidConfig, security);
break;
case "wpa3OnlyEAP":
security.put("mode", "3");
getRadiusConfiguration(opensyncApConfig, ssidConfig, security);
getRadiusAccountingConfiguration(opensyncApConfig, ssidConfig, security);
} else if (ssidSecurityMode.equals("wpa2EAP") || ssidSecurityMode.equals("wpa2Radius")
|| ssidSecurityMode.equals("wpa3MixedEAP")) {
security.put("mode", "mixed");
getRadiusConfiguration(opensyncApConfig, ssidConfig, security);
getRadiusAccountingConfiguration(opensyncApConfig, ssidConfig, security);
break;
case "wpa2EAP":
case "wpa2Radius":
case "wpa3MixedEAP":
security.put("mode", "mixed");
getRadiusConfiguration(opensyncApConfig, ssidConfig, security);
getRadiusAccountingConfiguration(opensyncApConfig, ssidConfig, security);
} else if (ssidSecurityMode.equals("wpaEAP") || ssidSecurityMode.equals("wpaRadius")) {
security.put("mode", "1");
getRadiusConfiguration(opensyncApConfig, ssidConfig, security);
getRadiusAccountingConfiguration(opensyncApConfig, ssidConfig, security);
} else if (ssidSecurityMode.equals("wep")) {
security.put("key", ssidConfig.getKeyStr());
security.put("mode", "1");
break;
case "wpaEAP":
case "wpaRadius":
security.put("mode", "1");
getRadiusConfiguration(opensyncApConfig, ssidConfig, security);
getRadiusAccountingConfiguration(opensyncApConfig, ssidConfig, security);
break;
}
}
}
@@ -1030,7 +884,7 @@ public class OvsdbSsidConfig extends OvsdbDaoBase {
for (OperationResult res : result) {
LOG.info("Op Result {}", res);
if (res instanceof UpdateResult) {
LOG.info("removeAllSsids:result {}", ((UpdateResult) res).toString());
LOG.info("removeAllSsids:result {}", res.toString());
} else if (res instanceof ErrorResult) {
LOG.error("removeAllSsids:result error {}", (res));
throw new RuntimeException("removeAllSsids " + ((ErrorResult) res).getError() + " "

View File

@@ -133,10 +133,8 @@ public class OpensyncGatewayTipWlanOvsdbClientTest {
Mockito.verify(ovsdbSession).getOvsdbClient();
Mockito.verify(opensyncExternalIntegrationInterface).getApConfig("Test_Client_21P10C68818122");
Mockito.verify(ovsdbDao).removeAllSsids(ovsdbClient);
Mockito.verify(ovsdbDao).removeAllStatsConfigs(ovsdbClient);
Mockito.verify(ovsdbDao).configureWifiRadios(ovsdbClient, apConfig);
Mockito.verify(ovsdbDao).configureSsids(ovsdbClient, apConfig);
Mockito.verify(ovsdbDao).configureStatsFromProfile(ovsdbClient, apConfig);
}

View File

@@ -1,6 +1,8 @@
package com.telecominfraproject.wlan.opensync.ovsdb.dao;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
@@ -14,55 +16,66 @@ import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import com.telecominfraproject.wlan.core.model.entity.CountryCode;
import com.telecominfraproject.wlan.core.model.equipment.EquipmentType;
import com.telecominfraproject.wlan.equipment.models.ApElementConfiguration;
import com.telecominfraproject.wlan.equipment.models.Equipment;
import com.telecominfraproject.wlan.location.models.Location;
import com.telecominfraproject.wlan.location.models.LocationDetails;
import com.telecominfraproject.wlan.location.models.LocationType;
import com.telecominfraproject.wlan.opensync.external.integration.models.OpensyncAPConfig;
import com.telecominfraproject.wlan.profile.models.Profile;
import com.telecominfraproject.wlan.profile.models.ProfileType;
import com.telecominfraproject.wlan.profile.network.models.ApNetworkConfiguration;
import com.telecominfraproject.wlan.profile.rf.models.RfConfiguration;
import com.telecominfraproject.wlan.profile.ssid.models.SsidConfiguration;
import com.vmware.ovsdb.protocol.operation.result.OperationResult;
import com.vmware.ovsdb.protocol.schema.DatabaseSchema;
import com.vmware.ovsdb.protocol.schema.TableSchema;
import com.vmware.ovsdb.service.OvsdbClient;
@RunWith(SpringRunner.class)
@ActiveProfiles(profiles = { "integration_test", }) // NOTE: these profiles will
// be ADDED to the list of
// active profiles
@SpringBootTest(webEnvironment = WebEnvironment.NONE, classes = OvsdbRadioConfigTest.class)
@Import(value = { OvsdbRadioConfig.class,OvsdbRadioConfigTest.Config.class,
@Import(value = { OvsdbRadioConfig.class, OvsdbRadioConfigTest.Config.class, OvsdbGet.class,
})
public class OvsdbRadioConfigTest {
@Autowired
OvsdbRadioConfig ovsdbRadioConfig;
@MockBean(answer = Answers.RETURNS_DEEP_STUBS)
OvsdbGet ovsdbGet;
@Mock(answer = Answers.RETURNS_MOCKS)
CompletableFuture<OperationResult[]> selectionFutureResult;
@Mock(answer = Answers.RETURNS_MOCKS)
CompletableFuture<DatabaseSchema> getSchemaResult;
@Mock(answer = Answers.RETURNS_MOCKS)
DatabaseSchema databaseSchema;
@Mock(answer = Answers.RETURNS_MOCKS)
Map<String,TableSchema> tableSchemaMap;
Map<String, TableSchema> tableSchemaMap;
@Mock(answer = Answers.RETURNS_MOCKS)
TableSchema tableSchema;
@Mock(answer = Answers.RETURNS_MOCKS)
OvsdbClient ovsdbClient;
OpensyncAPConfig opensyncAPConfig;
@Configuration
// @PropertySource({ "classpath:persistence-${envTarget:dev}.properties" })
static class Config {
@@ -72,16 +85,60 @@ public class OvsdbRadioConfigTest {
return new OvsdbRadioConfig();
}
}
@Before
public void setUp() throws Exception {
Mockito.when(selectionFutureResult.get(Mockito.anyLong(), Mockito.eq(TimeUnit.SECONDS))).thenReturn(new OperationResult[0]);
Mockito.when(selectionFutureResult.get(Mockito.anyLong(), Mockito.eq(TimeUnit.SECONDS)))
.thenReturn(new OperationResult[0]);
Mockito.when(ovsdbClient.transact(Mockito.eq(OvsdbDao.ovsdbName), Mockito.anyList()))
.thenReturn(selectionFutureResult);
.thenReturn(selectionFutureResult);
Mockito.when(tableSchemaMap.get(Mockito.anyString())).thenReturn(tableSchema);
Mockito.when(databaseSchema.getTables()).thenReturn(tableSchemaMap);
Mockito.when(getSchemaResult.get()).thenReturn(databaseSchema);
Mockito.when(ovsdbClient.getSchema(OvsdbDaoBase.ovsdbName)).thenReturn(getSchemaResult);
opensyncAPConfig = new OpensyncAPConfig();
Equipment ce = new Equipment();
ce.setEquipmentType(EquipmentType.AP);
ce.setDetails(ApElementConfiguration.createWithDefaults());
ce.setProfileId(8);
ce.setLocationId(8L);
opensyncAPConfig.setCustomerEquipment(ce);
Location equipmentLocation = new Location();
equipmentLocation.setCustomerId(2);
equipmentLocation.setId(8);
equipmentLocation.setDetails(LocationDetails.createWithDefaults());
equipmentLocation.setLocationType(LocationType.COUNTRY);
equipmentLocation.setName("location");
opensyncAPConfig.setEquipmentLocation(equipmentLocation);
Profile ssidProfile = new Profile();
ssidProfile.setId(2);
ssidProfile.setName("ssid-profile");
ssidProfile.setProfileType(ProfileType.ssid);
ssidProfile.setDetails(SsidConfiguration.createWithDefaults());
opensyncAPConfig.setSsidProfile(List.of(ssidProfile));
Profile rfProfile = new Profile();
rfProfile.setId(4);
rfProfile.setName("rf-profile");
rfProfile.setDetails(RfConfiguration.createWithDefaults());
rfProfile.setProfileType(ProfileType.rf);
opensyncAPConfig.setRfProfile(rfProfile);
Profile apProfile = new Profile();
apProfile.setId(8);
apProfile.setCustomerId(2);
apProfile.setDetails(ApNetworkConfiguration.createWithDefaults());
apProfile.setProfileType(ProfileType.equipment_ap);
apProfile.setName("ap-profile");
apProfile.setChildProfileIds(Set.of(2L, 4L));
opensyncAPConfig.setApProfile(apProfile);
}
@After
@@ -90,22 +147,7 @@ public class OvsdbRadioConfigTest {
@Test
public void testConfigureWifiRadiosOvsdbClientOpensyncAPConfig() throws Exception {
OpensyncAPConfig opensyncAPConfig = constructOpensyncAPConfig();
ovsdbRadioConfig.configureWifiRadios(ovsdbClient, opensyncAPConfig);
}
OpensyncAPConfig constructOpensyncAPConfig() {
ApElementConfiguration equipmentDetails = Mockito.mock(ApElementConfiguration.class, Mockito.RETURNS_MOCKS);
RfConfiguration rfConfig = Mockito.mock(RfConfiguration.class, Mockito.RETURNS_MOCKS);
Profile rfProfile = Mockito.mock(Profile.class, Mockito.RETURNS_MOCKS);
Mockito.when(rfProfile.getDetails()).thenReturn(rfConfig);
Equipment equipment = Mockito.mock(Equipment.class);
Mockito.when(equipment.getDetails()).thenReturn(equipmentDetails);
OpensyncAPConfig opensyncAPConfig = Mockito.mock(OpensyncAPConfig.class, Mockito.RETURNS_MOCKS);
Mockito.when(opensyncAPConfig.getCountryCode()).thenReturn(CountryCode.CA.getName());
Mockito.when(opensyncAPConfig.getCustomerEquipment()).thenReturn(equipment);
Mockito.when(opensyncAPConfig.getRfProfile()).thenReturn(rfProfile);
return opensyncAPConfig;
}
}