OpensyncGateway changes to only treat clients which appear in

Wifi_Associated_Clients table as clients which can be added to the
cloud's client and client session lists. Other changes through either
stats changes or via other tables in ovsdb can only alter existing
clients and sessions. Else they are ignored.
SSIDs and InetConfig for SSIDs are not automatically deleted if an
existing configuration for this AP containing profiles for the ssids exists on the cloud.
This commit is contained in:
Mike Hansen
2020-11-02 16:04:41 -05:00
parent 6c784367ed
commit 1d7f822ed4
5 changed files with 416 additions and 484 deletions

View File

@@ -1228,10 +1228,9 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
activeBssidsStatus = statusServiceInterface.update(activeBssidsStatus);
if (LOG.isTraceEnabled()) {
LOG.trace("Processing Wifi_VIF_State table update for AP {}, updated ACTIVE_BSSID Status {}", apId,
activeBssidsStatus.toPrettyString());
}
LOG.info("Processing Wifi_VIF_State table update for AP {}, updated ACTIVE_BSSID Status {}", apId,
activeBssidsStatus);
}
@Override
@@ -1415,9 +1414,6 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
isReassociation = false;
}
ClientInfoDetails clientDetails = (ClientInfoDetails) clientInstance.getDetails();
clientInstance.setDetails(clientDetails);
clientInstance = clientServiceInterface.update(clientInstance);
@@ -1432,16 +1428,13 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
clientSession.setLocationId(ce.getLocationId());
ClientSessionDetails clientSessionDetails = new ClientSessionDetails();
clientSessionDetails.setIsReassociation(isReassociation);
clientSessionDetails.setSessionId(clientInstance.getMacAddress().getAddressAsLong());
clientSession.setDetails(clientSessionDetails);
clientSession = clientServiceInterface.updateSession(clientSession);
}
ClientSessionDetails clientSessionDetails = clientSession.getDetails();
clientSessionDetails.setAssociationState(AssociationState._802_11_Associated);
clientSessionDetails.setAssocTimestamp(System.currentTimeMillis());
clientSessionDetails.setSessionId(clientInstance.getMacAddress().getAddressAsLong());
clientSession.getDetails().mergeSession(clientSessionDetails);
clientSession = clientServiceInterface.updateSession(clientSession);
@@ -1772,29 +1765,29 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
return;
}
Set<MacAddress> macAddressSet = new HashSet<>();
macAddressSet.add(new MacAddress(deletedClientMac));
List<ClientSession> clientSessionList = clientServiceInterface.getSessions(customerId, macAddressSet);
com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface.getOrNull(customerId,
new MacAddress(deletedClientMac));
ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId,
new MacAddress(deletedClientMac));
for (ClientSession session : clientSessionList) {
if (client != null) {
if (clientSession != null) {
if (!clientSession.getDetails().getAssociationState().equals(AssociationState.Disconnected)) {
clientSession.getDetails().setAssociationState(AssociationState.Disconnected);
clientSession = clientServiceInterface.updateSession(clientSession);
LOG.info("Session {} for client {} is now disconnected.", clientSession, client.getMacAddress());
}
}
} else {
if (clientSession != null) {
ClientSessionDetails clientSessionDetails = session.getDetails();
clientSession = clientServiceInterface.deleteSession(customerId, equipmentId,
new MacAddress(deletedClientMac));
if ((clientSessionDetails.getAssociationState() != null)
&& !clientSessionDetails.getAssociationState().equals(AssociationState.Disconnected)) {
clientSessionDetails.setDisconnectByClientTimestamp(System.currentTimeMillis());
clientSessionDetails.setAssociationState(AssociationState.Disconnected);
session.setDetails(clientSessionDetails);
session = clientServiceInterface.updateSession(session);
if (LOG.isTraceEnabled()) {
LOG.trace("wifiAssociatedClientsDbTableDelete Updated client session, set to disconnected {}",
session.toPrettyString());
LOG.info("No client {} found, delete session {}", new MacAddress(deletedClientMac), clientSession);
}
}
}
}
@@ -1839,13 +1832,17 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
continue;
}
MacAddress clientMacAddress = new MacAddress(dhcpLeasedIps.get("hwaddr"));
if (clientMacAddress.equals(equipmentServiceInterface.get(equipmentId).getBaseMacAddress())) {
com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface.getOrNull(customerId,
clientMacAddress);
if (client == null) {
LOG.info("Cannot find client instance for {}", clientMacAddress);
continue;
} else if (clientMacAddress.equals(equipmentServiceInterface.get(equipmentId).getBaseMacAddress())) {
LOG.info("Not a client device {} ", dhcpLeasedIps);
com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface
.getOrNull(customerId, clientMacAddress);
if (client != null) {
// In case somehow this equipment has accidentally been
// tagged as a client, remove
@@ -1858,15 +1855,11 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
clientServiceInterface.deleteSession(customerId, equipmentId, clientMacAddress));
}
LOG.info("Deleting invalid client {}",
clientServiceInterface.delete(customerId, clientMacAddress));
LOG.info("Deleting invalid client {}", clientServiceInterface.delete(customerId, clientMacAddress));
}
continue;
}
com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface.getOrNull(customerId,
clientMacAddress);
if (client != null) {
} else {
LOG.info("Client {} already exists on the cloud, update client values", dhcpLeasedIps);
ClientInfoDetails clientDetails = (ClientInfoDetails) client.getDetails();
@@ -1902,6 +1895,7 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
// In this case, we might have a session, as the client
// already exists on the cloud, update if required
ClientSession session = updateClientSession(customerId, equipmentId, locationId, dhcpLeasedIps,
clientMacAddress);
if (session != null) {
@@ -1909,15 +1903,61 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
}
}
}
if (!clientSessionList.isEmpty()) {
LOG.info("Updating client sessions {}", clientSessionList);
clientSessionList = clientServiceInterface.updateSessions(clientSessionList);
LOG.info("Updated client sessions {}", clientSessionList);
}
} else if (rowUpdateOperation.equals(RowUpdateOperation.MODIFY)
|| rowUpdateOperation.equals(RowUpdateOperation.INIT)) {
List<ClientSession> clientSessionList = new ArrayList<>();
for (Map<String, String> dhcpLeasedIps : dhcpAttributes) {
if (!dhcpLeasedIps.containsKey("hwaddr")) {
LOG.info("Cannot update a client {} that has no hwaddr.", dhcpLeasedIps);
continue;
}
MacAddress clientMacAddress = new MacAddress(dhcpLeasedIps.get("hwaddr"));
com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface.getOrNull(customerId,
clientMacAddress);
if (client == null) {
LOG.info("Cannot find client instance for {}", clientMacAddress);
continue;
} else if (clientMacAddress.equals(equipmentServiceInterface.get(equipmentId).getBaseMacAddress())) {
LOG.info("Not a client device {} ", dhcpLeasedIps);
// In case somehow this equipment has accidentally been
// tagged as a client, remove
ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId,
clientMacAddress);
if (clientSession != null) {
LOG.info("Deleting invalid client session {}",
clientServiceInterface.deleteSession(customerId, equipmentId, clientMacAddress));
}
LOG.info("Deleting invalid client {}", clientServiceInterface.delete(customerId, clientMacAddress));
continue;
} else {
client = new com.telecominfraproject.wlan.client.models.Client();
client.setCustomerId(customerId);
client.setMacAddress(clientMacAddress);
ClientInfoDetails clientDetails = new ClientInfoDetails();
ClientInfoDetails clientDetails = (ClientInfoDetails) client.getDetails();
if (dhcpLeasedIps.containsKey("hostname")) {
clientDetails.setHostName(dhcpLeasedIps.get("hostname"));
@@ -1944,109 +1984,6 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
client.setDetails(clientDetails);
client = clientServiceInterface.create(client);
LOG.info("Created Client {}.", client);
}
// we might have a session, update if required
ClientSession session = updateClientSession(customerId, equipmentId, locationId, dhcpLeasedIps,
clientMacAddress);
if (session != null) {
clientSessionList.add(session);
}
}
if (!clientSessionList.isEmpty()) {
LOG.info("Updating client sessions {}", clientSessionList);
clientSessionList = clientServiceInterface.updateSessions(clientSessionList);
LOG.info("Updated client sessions {}", clientSessionList);
}
} else if (rowUpdateOperation.equals(RowUpdateOperation.MODIFY)
|| rowUpdateOperation.equals(RowUpdateOperation.INIT)) {
List<ClientSession> clientSessionList = new ArrayList<>();
for (Map<String, String> dhcpLeasedIps : dhcpAttributes) {
if (!dhcpLeasedIps.containsKey("hwaddr")) {
LOG.info("Cannot update a client {} that has no hwaddr.", dhcpLeasedIps);
continue;
}
MacAddress clientMacAddress = new MacAddress(dhcpLeasedIps.get("hwaddr"));
if (clientMacAddress.equals(equipmentServiceInterface.get(equipmentId).getBaseMacAddress())) {
LOG.info("Not a client device {} ", dhcpLeasedIps);
com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface
.getOrNull(customerId, clientMacAddress);
if (client != null) {
// In case somehow this equipment has accidentally been
// tagged as a client, remove
ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId,
clientMacAddress);
if (clientSession != null) {
LOG.info("Deleting invalid client session {}",
clientServiceInterface.deleteSession(customerId, equipmentId, clientMacAddress));
}
LOG.info("Deleting invalid client {}",
clientServiceInterface.delete(customerId, clientMacAddress));
}
continue;
}
com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface.getOrNull(customerId,
clientMacAddress);
if (client == null) {
LOG.info("Client {} does not exist on the cloud. Creating...", dhcpLeasedIps);
client = new com.telecominfraproject.wlan.client.models.Client();
client.setCustomerId(customerId);
client.setMacAddress(clientMacAddress);
ClientInfoDetails clientDetails = new ClientInfoDetails();
client.setDetails(clientDetails);
client = clientServiceInterface.create(client);
}
ClientInfoDetails clientDetails = (ClientInfoDetails) client.getDetails();
if (dhcpLeasedIps.containsKey("hostname")) {
clientDetails.setHostName(dhcpLeasedIps.get("hostname"));
}
if (dhcpLeasedIps.containsKey("fingerprint")) {
clientDetails.setApFingerprint(dhcpLeasedIps.get("fingerprint"));
}
if (dhcpLeasedIps.containsKey("device_type")) {
DhcpFpDeviceType dhcpFpDeviceType = DhcpFpDeviceType.getByName(dhcpLeasedIps.get("device_type"));
ClientType clientType = OvsdbToWlanCloudTypeMappingUtility
.getClientTypeForDhcpFpDeviceType(dhcpFpDeviceType);
LOG.debug("Translate from ovsdb {} to cloud {}", dhcpFpDeviceType, clientType);
clientDetails.setClientType(clientType.getId());
}
client.setDetails(clientDetails);
client = clientServiceInterface.update(client);
LOG.info("Updated Client {}.", client);
@@ -2059,6 +1996,7 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
clientSessionList.add(session);
}
}
}
@@ -2096,7 +2034,7 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
//         "manuf_id":
if (session == null) {
session = new ClientSession();
return null;
}
session.setCustomerId(customerId);
session.setEquipmentId(equipmentId);

View File

@@ -1891,8 +1891,8 @@ public class OpensyncExternalIntegrationMqttMessageProcessor {
}
}
void handleClientSessionMetricsUpdate(int customerId, long equipmentId, long locationId, RadioType radioType,
long timestamp, sts.OpensyncStats.Client client) {
ClientSession handleClientSessionMetricsUpdate(int customerId, long equipmentId, long locationId,
RadioType radioType, long timestamp, sts.OpensyncStats.Client client) {
try
{
@@ -1904,13 +1904,10 @@ public class OpensyncExternalIntegrationMqttMessageProcessor {
boolean isReassociation = true;
if (clientInstance == null) {
clientInstance = new com.telecominfraproject.wlan.client.models.Client();
clientInstance.setCustomerId(customerId);
clientInstance.setMacAddress(new MacAddress(client.getMacAddress()));
clientInstance.setDetails(new ClientInfoDetails());
clientInstance = clientServiceInterface.create(clientInstance);
isReassociation = false;
LOG.info("Cannot get client instance for {}", client.getMacAddress());
return null;
}
LOG.info("Client {}", clientInstance);
@@ -1919,18 +1916,8 @@ public class OpensyncExternalIntegrationMqttMessageProcessor {
clientInstance.getMacAddress());
if (clientSession == null) {
clientSession = new ClientSession();
clientSession.setCustomerId(customerId);
clientSession.setEquipmentId(equipmentId);
clientSession.setLocationId(locationId);
clientSession.setMacAddress(clientInstance.getMacAddress());
ClientSessionDetails clientSessionDetails = new ClientSessionDetails();
clientSessionDetails.setSsid(client.getSsid());
clientSessionDetails.setRadioType(radioType);
clientSessionDetails.setSessionId(clientInstance.getMacAddress().getAddressAsLong());
clientSession.setDetails(new ClientSessionDetails());
clientSession = clientServiceInterface.updateSession(clientSession);
LOG.info("Cannot get client session for {}", clientInstance.getMacAddress());
return null;
}
ClientSessionDetails latestClientSessionDetails = clientSession.getDetails();
@@ -1961,7 +1948,6 @@ public class OpensyncExternalIntegrationMqttMessageProcessor {
}).collect(Collectors.toList());
if (!ssidConfigList.isEmpty()) {
Profile ssidProfile = ssidConfigList.iterator().next();
SsidConfiguration ssidConfig = (SsidConfiguration) ssidProfile.getDetails();
if (ssidConfig.getSecureMode().equals(SecureMode.open)) {
@@ -1979,7 +1965,6 @@ public class OpensyncExternalIntegrationMqttMessageProcessor {
|| ssidConfig.getSecureMode().equals(SecureMode.wpa2EAP)
|| ssidConfig.getSecureMode().equals(SecureMode.wpa2OnlyEAP)) {
latestClientSessionDetails.setSecurityType(SecurityType.RADIUS);
latestClientSessionDetails.setEapDetails(new ClientEapDetails());
} else {
latestClientSessionDetails.setSecurityType(SecurityType.UNSUPPORTED);
@@ -2009,9 +1994,11 @@ public class OpensyncExternalIntegrationMqttMessageProcessor {
LOG.debug("Updated client session {}", clientSession);
return clientSession;
} catch (Exception e) {
LOG.error("Error while attempting to create ClientSession and Info", e);
}
return null;
}
ClientSessionMetricDetails calculateClientSessionMetricDetails(sts.OpensyncStats.Client client, long timestamp) {
@@ -2134,9 +2121,11 @@ public class OpensyncExternalIntegrationMqttMessageProcessor {
if (client.hasConnected() && client.getConnected() && client.hasMacAddress()) {
// update metrics for connected client
numConnectedClients += 1;
handleClientSessionMetricsUpdate(customerId, equipmentId, locationId, radioType,
ClientSession session = handleClientSessionMetricsUpdate(customerId, equipmentId, locationId, radioType,
clientReport.getTimestampMs(), client);
if (session != null) {
numConnectedClients += 1;
}
} else {
// Make sure, if we have a session for this client,
// it

View File

@@ -193,14 +193,15 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
LOG.debug("Client {} connect for AP {}", clientCn, apId);
ovsdbDao.removeAllStatsConfigs(ovsdbClient); // always
ovsdbDao.removeAllSsids(ovsdbClient); // always
ovsdbDao.removeWifiRrm(ovsdbClient);
OpensyncAPConfig opensyncAPConfig = extIntegrationInterface.getApConfig(apId);
if (opensyncAPConfig != null) {
ovsdbDao.removeAllPasspointConfigs(ovsdbClient);
ovsdbDao.removeAllStatsConfigs(ovsdbClient); // always
ovsdbDao.removeAllSsids(ovsdbClient, opensyncAPConfig); // always
ovsdbDao.removeWifiRrm(ovsdbClient);
ovsdbDao.configureWifiRadios(ovsdbClient, opensyncAPConfig);
ovsdbDao.configureInterfaces(ovsdbClient);
ovsdbDao.configureSsids(ovsdbClient, opensyncAPConfig);
ovsdbDao.configureWifiRrm(ovsdbClient, opensyncAPConfig);
if (opensyncAPConfig.getHotspotConfig() != null) {
@@ -210,10 +211,13 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
if (((ApNetworkConfiguration) opensyncAPConfig.getApProfile().getDetails()).getSyntheticClientEnabled()) {
ovsdbDao.enableNetworkProbeForSyntheticClient(ovsdbClient);
}
} else {
ovsdbDao.removeAllPasspointConfigs(ovsdbClient);
ovsdbDao.removeAllStatsConfigs(ovsdbClient); // always
ovsdbDao.removeAllSsids(ovsdbClient); // always
ovsdbDao.removeWifiRrm(ovsdbClient);
}
ovsdbDao.configureInterfaces(ovsdbClient);
if (ovsdbDao.getDeviceStatsReportingInterval(ovsdbClient) != collectionIntervalSecDeviceStats) {
ovsdbDao.updateDeviceStatsReportingInterval(ovsdbClient, collectionIntervalSecDeviceStats);
}
@@ -262,18 +266,18 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
return;
}
ovsdbDao.removeAllSsids(ovsdbClient); // always
ovsdbDao.removeAllPasspointConfigs(ovsdbClient);
ovsdbDao.removeAllSsids(ovsdbClient, opensyncAPConfig); // always
ovsdbDao.removeWifiRrm(ovsdbClient);
ovsdbDao.removeAllStatsConfigs(ovsdbClient); // always
ovsdbDao.configureWifiRadios(ovsdbClient, opensyncAPConfig);
ovsdbDao.configureInterfaces(ovsdbClient);
ovsdbDao.configureSsids(ovsdbClient, opensyncAPConfig);
ovsdbDao.configureWifiRrm(ovsdbClient, opensyncAPConfig);
if (opensyncAPConfig.getHotspotConfig() != null) {
ovsdbDao.configureHotspots(ovsdbClient, opensyncAPConfig);
}
ovsdbDao.configureInterfaces(ovsdbClient);
ovsdbDao.configureStatsFromProfile(ovsdbClient, opensyncAPConfig);
if (ovsdbDao.getDeviceStatsReportingInterval(ovsdbClient) != collectionIntervalSecDeviceStats) {
ovsdbDao.updateDeviceStatsReportingInterval(ovsdbClient, collectionIntervalSecDeviceStats);
@@ -507,7 +511,7 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
private void monitorAwlanNodeDbTable(OvsdbClient ovsdbClient, String key) throws OvsdbClientException {
CompletableFuture<TableUpdates> awCf = ovsdbClient.monitor(OvsdbDao.ovsdbName,
OvsdbDao.awlanNodeDbTable + "_" + key,
new MonitorRequests(ImmutableMap.of(OvsdbDao.awlanNodeDbTable, new MonitorRequest())),
new MonitorRequests(ImmutableMap.of(OvsdbDao.awlanNodeDbTable, new MonitorRequest(new MonitorSelect(true, false, false, true)))),
new MonitorCallback() {
@Override
@@ -615,7 +619,7 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
CompletableFuture<TableUpdates> rsCf = ovsdbClient.monitor(OvsdbDao.ovsdbName,
OvsdbDao.wifiRadioStateDbTable + "_" + key,
new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiRadioStateDbTable, new MonitorRequest())),
new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiRadioStateDbTable, new MonitorRequest(new MonitorSelect(true, false, false, true)))),
new MonitorCallback() {
@Override
@@ -636,7 +640,7 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
CompletableFuture<TableUpdates> vsCf = ovsdbClient.monitor(OvsdbDao.ovsdbName,
OvsdbDao.wifiVifStateDbTable + "_" + key,
new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiVifStateDbTable, new MonitorRequest())),
new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiVifStateDbTable, new MonitorRequest(new MonitorSelect(true, true, true, true)))),
new MonitorCallback() {
@Override

View File

@@ -298,7 +298,9 @@ public class OvsdbDao {
// when not found - look them up for if_name = br-lan
fillInWanIpAddressAndMac(ovsdbClient, ret, defaultLanInterfaceType, defaultLanInterfaceName);
if (ret.ipV4Address == null) throw new RuntimeException("Could not get inet address for Lan and Wan network interfaces. Node is not ready to connect.");
if (ret.ipV4Address == null)
throw new RuntimeException(
"Could not get inet address for Lan and Wan network interfaces. Node is not ready to connect.");
}
fillInLanIpAddressAndMac(ovsdbClient, ret, defaultLanInterfaceType);
@@ -973,88 +975,6 @@ public class OvsdbDao {
return ret;
}
public Map<String, PortInfo> getProvisionedPorts(OvsdbClient ovsdbClient) {
Map<String, PortInfo> ret = new HashMap<>();
List<Operation> operations = new ArrayList<>();
List<Condition> conditions = new ArrayList<>();
List<String> columns = new ArrayList<>();
columns.add("name");
columns.add("_uuid");
columns.add("interfaces");
try {
LOG.debug("Retrieving Ports:");
operations.add(new Select(portDbTable, conditions, columns));
CompletableFuture<OperationResult[]> fResult = ovsdbClient.transact(ovsdbName, operations);
OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS);
for (OperationResult res : result) {
LOG.debug("Op Result {}", res);
}
for (Row row : ((SelectResult) result[0]).getRows()) {
PortInfo portInfo = new PortInfo();
portInfo.name = row.getStringColumn("name");
portInfo.uuid = row.getUuidColumn("_uuid");
portInfo.interfaceUuids = row.getSetColumn("interfaces");
ret.put(portInfo.name, portInfo);
}
LOG.debug("Retrieved Ports: {}", ret);
} catch (ExecutionException | InterruptedException | OvsdbClientException | TimeoutException e) {
LOG.error("Error in getProvisionedPorts", e);
throw new RuntimeException(e);
}
return ret;
}
public Map<String, BridgeInfo> getProvisionedBridges(OvsdbClient ovsdbClient) {
Map<String, BridgeInfo> ret = new HashMap<>();
List<Operation> operations = new ArrayList<>();
List<Condition> conditions = new ArrayList<>();
List<String> columns = new ArrayList<>();
columns.add("name");
columns.add("_uuid");
columns.add("ports");
try {
LOG.debug("Retrieving Bridges:");
operations.add(new Select(bridgeDbTable, conditions, columns));
CompletableFuture<OperationResult[]> fResult = ovsdbClient.transact(ovsdbName, operations);
OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS);
for (OperationResult res : result) {
LOG.debug("Op Result {}", res);
}
for (Row row : ((SelectResult) result[0]).getRows()) {
BridgeInfo bridgeInfo = new BridgeInfo();
bridgeInfo.name = row.getStringColumn("name");
bridgeInfo.uuid = row.getUuidColumn("_uuid");
bridgeInfo.portUuids = row.getSetColumn("ports");
ret.put(bridgeInfo.name, bridgeInfo);
}
LOG.debug("Retrieved Bridges: {}", ret);
} catch (ExecutionException | InterruptedException | OvsdbClientException | TimeoutException e) {
LOG.error("Error in getProvisionedBridges", e);
throw new RuntimeException(e);
}
return ret;
}
public Map<String, CommandConfigInfo> getProvisionedCommandConfigs(OvsdbClient ovsdbClient) {
Map<String, CommandConfigInfo> ret = new HashMap<>();
@@ -1779,62 +1699,106 @@ public class OvsdbDao {
}
}
public void provisionBridgePortInterface(OvsdbClient ovsdbClient) {
public void removeAllSsids(OvsdbClient ovsdbClient, OpensyncAPConfig opensyncAPConfig) {
Map<String, WifiVifConfigInfo> currentWifiVifConfigInfo = getProvisionedWifiVifConfigs(ovsdbClient);
Map<String, WifiRadioConfigInfo> currentWifiRadioConfigInfo = getProvisionedWifiRadioConfigs(ovsdbClient);
List<WifiVifConfigInfo> vifConfigsToDelete = new ArrayList<>();
for (Entry<String, WifiVifConfigInfo> vifConfigInfo : currentWifiVifConfigInfo.entrySet()) {
LOG.debug("Checking {}", vifConfigInfo.getKey());
WifiRadioConfigInfo radioConfigInfo = null;
if (vifConfigInfo.getValue().ifName.startsWith(defaultRadio0)) {
radioConfigInfo = currentWifiRadioConfigInfo.get(radio0);
} else if (vifConfigInfo.getValue().ifName.startsWith(defaultRadio1)) {
radioConfigInfo = currentWifiRadioConfigInfo.get(radio1);
} else if (vifConfigInfo.getValue().ifName.startsWith(defaultRadio2)) {
radioConfigInfo = currentWifiRadioConfigInfo.get(radio2);
}
boolean delete = true;
if (radioConfigInfo != null) {
final String freqBand = radioConfigInfo.freqBand;
if (radioConfigInfo.vifConfigUuids.contains(vifConfigInfo.getValue().uuid)) {
if (opensyncAPConfig.getSsidProfile().stream().anyMatch(new Predicate<Profile>() {
@Override
public boolean test(Profile t) {
SsidConfiguration ssidConfig = (SsidConfiguration) t.getDetails();
return (ssidConfig.getSsid().equals(vifConfigInfo.getValue().ssid))
&& (ssidConfig.getAppliedRadios().contains(OvsdbToWlanCloudTypeMappingUtility
.getRadioTypeForOvsdbRadioFreqBand(freqBand)));
}
})) {
delete = false;
LOG.debug("Do not delete vif {}", vifConfigInfo.getValue());
}
}
}
if (delete) {
vifConfigsToDelete.add(vifConfigInfo.getValue());
}
}
LOG.debug("The following VIFs should be deleted {}", vifConfigsToDelete);
List<Operation> operations = new ArrayList<>();
for (WifiVifConfigInfo vifConfigInfo : vifConfigsToDelete) {
List<Condition> conditions = new ArrayList<>();
conditions.add(new Condition("_uuid", Function.EQUALS, new Atom<>(vifConfigInfo.uuid)));
operations.add(new Delete(wifiVifConfigDbTable, conditions));
}
try {
CompletableFuture<OperationResult[]> fResult = ovsdbClient.transact(ovsdbName, operations);
OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS);
String patchW2h = "patch-w2h";
String patchH2w = "patch-h2w";
Map<String, InterfaceInfo> provisionedInterfaces = getProvisionedInterfaces(ovsdbClient);
if (provisionedInterfaces.isEmpty()) {
LOG.debug("No Interfaces defined in Ovsdb. Cannot perform Bridge/Port/Interface mapping.");
return;
if (LOG.isDebugEnabled()) {
LOG.debug("Removed existing SSIDs from {}:", wifiVifConfigDbTable);
for (OperationResult res : result) {
LOG.debug("Op Result {}", res);
}
LOG.debug("Existing Interfaces: {}", provisionedInterfaces.keySet());
Map<String, PortInfo> provisionedPorts = getProvisionedPorts(ovsdbClient);
if (provisionedInterfaces.isEmpty()) {
LOG.debug("No Ports defined in Ovsdb. Cannot perform Bridge/Port/Interface mapping.");
return;
}
LOG.debug("Existing Ports: {}", provisionedPorts.keySet());
Map<String, BridgeInfo> provisionedBridges = getProvisionedBridges(ovsdbClient);
if (provisionedInterfaces.isEmpty()) {
LOG.debug("No Bridges defined in Ovsdb. Cannot perform Bridge/Port/Interface mapping.");
return;
operations = new ArrayList<>();
// Add vifs to delete
for (WifiVifConfigInfo vifConfigInfo : vifConfigsToDelete) {
List<Condition> conditions = new ArrayList<>();
conditions.add(new Condition("if_name", Function.EQUALS, new Atom<>(vifConfigInfo.ifName)));
operations.add(new Delete(wifiInetConfigDbTable, conditions));
}
LOG.debug("Existing Bridges: {}", provisionedBridges.keySet());
Map<String, String> patchH2wOptions = new HashMap<>();
patchH2wOptions.put("peer", "patch-w2h");
fResult = ovsdbClient.transact(ovsdbName, operations);
result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS);
Map<String, String> patchW2hOptions = new HashMap<>();
patchH2wOptions.put("peer", "patch-h2w");
if (LOG.isDebugEnabled()) {
LOG.debug("Removed existing InetConfigs from {}:", wifiVifConfigDbTable);
provisionSingleBridgePortInterface(ovsdbClient, patchH2w, bridgeNameVifInterfaces, "patch", patchH2wOptions,
provisionedInterfaces, provisionedPorts, provisionedBridges);
provisionSingleBridgePortInterface(ovsdbClient, patchW2h, defaultWanInterfaceType, "patch", patchW2hOptions,
provisionedInterfaces, provisionedPorts, provisionedBridges);
provisionSingleBridgePortInterface(ovsdbClient, defaultRadio0, bridgeNameVifInterfaces, "vif", null,
provisionedInterfaces, provisionedPorts, provisionedBridges);
provisionSingleBridgePortInterface(ovsdbClient, defaultRadio1, bridgeNameVifInterfaces, "vif", null,
provisionedInterfaces, provisionedPorts, provisionedBridges);
provisionSingleBridgePortInterface(ovsdbClient, defaultRadio2, bridgeNameVifInterfaces, "vif", null,
provisionedInterfaces, provisionedPorts, provisionedBridges);
for (OperationResult res : result) {
LOG.debug("Op Result {}", res);
}
}
} catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) {
LOG.error("Error in provisionBridgePortInterface", e);
} catch (OvsdbClientException | InterruptedException | ExecutionException | TimeoutException e) {
LOG.error("Error in removeAllSsids", e);
throw new RuntimeException(e);
}
}
public void removeAllSsids(OvsdbClient ovsdbClient) {
try {
removeAllHotspot20Config(ovsdbClient);
removeAllHotspot20OsuProviders(ovsdbClient);
removeAllHotspot20IconConfig(ovsdbClient);
removeAllPasspointConfigs(ovsdbClient);
List<Operation> operations = new ArrayList<>();
@@ -1893,6 +1857,12 @@ public class OvsdbDao {
}
public void removeAllPasspointConfigs(OvsdbClient ovsdbClient) {
removeAllHotspot20Config(ovsdbClient);
removeAllHotspot20OsuProviders(ovsdbClient);
removeAllHotspot20IconConfig(ovsdbClient);
}
public void configureWifiRadios(OvsdbClient ovsdbClient, OpensyncAPConfig opensyncAPConfig) {
String country = opensyncAPConfig.getCountryCode(); // should be the
@@ -2615,7 +2585,7 @@ public class OvsdbDao {
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) {
Map<Short, Set<String>> bonjourServiceMap, boolean isUpdate) {
List<Operation> operations = new ArrayList<>();
Map<String, Value> updateColumns = new HashMap<>();
@@ -2718,13 +2688,30 @@ public class OvsdbDao {
updateBlockList(updateColumns, macBlockList);
Row row = new Row(updateColumns);
//////
if (isUpdate) {
List<Condition> conditions = new ArrayList<>();
conditions.add(new Condition("if_name", Function.EQUALS, new Atom<>(vifInterfaceName)));
operations.add(new Update(wifiVifConfigDbTable, conditions, row));
} else {
operations.add(new Insert(wifiVifConfigDbTable, row));
}
CompletableFuture<OperationResult[]> fResult = ovsdbClient.transact(ovsdbName, operations);
OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS);
LOG.debug("Provisioned SSID {} on {}", ssid, vifInterfaceName);
if (isUpdate) {
for (OperationResult res : result) {
LOG.debug("Op Result {}", res);
}
LOG.info("Updated existing SSID {} on interface {} / {}", ssid, vifInterfaceName, radioFreqBand);
} else {
Uuid vifConfigUuid = null;
for (OperationResult res : result) {
LOG.debug("Op Result {}", res);
@@ -2732,14 +2719,14 @@ public class OvsdbDao {
vifConfigUuid = ((InsertResult) res).getUuid();
}
}
if (vifConfigUuid == null) {
throw new IllegalStateException("Wifi_VIF_Config entry was not created successfully");
}
updateColumns.clear();
operations.clear();
updateVifConfigsSetForRadio(ovsdbClient, ssid, radioFreqBand, operations, updateColumns, vifConfigUuid);
LOG.info("Provisioned SSID {} on interface {} / {}", ssid, vifInterfaceName, radioFreqBand);
}
Map<String, WifiInetConfigInfo> inetConfigs = getProvisionedWifiInetConfigs(ovsdbClient);
@@ -2751,12 +2738,11 @@ public class OvsdbDao {
(networkForwardMode == NetworkForwardMode.NAT));
}
LOG.info("Provisioned SSID {} on interface {} / {}", ssid, vifInterfaceName, radioFreqBand);
} catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) {
LOG.error("Error in configureSingleSsid", e);
throw new RuntimeException(e);
}
}
private void updateBlockList(Map<String, Value> updateColumns, List<MacAddress> macBlockList) {
@@ -3093,6 +3079,19 @@ public class OvsdbDao {
boolean enabled = ssidConfig.getSsidAdminState().equals(StateSetting.enabled);
try {
boolean isUpdate = false;
Map<String, WifiVifConfigInfo> provisionedVifs = getProvisionedWifiVifConfigs(ovsdbClient);
for (String key : provisionedVifs.keySet()) {
if (key.contains(ifName) && key.contains(ssidConfig.getSsid())) {
isUpdate = true;
ifName = provisionedVifs.get(key).ifName;
break;
}
}
if (!isUpdate) {
int numberOfInterfaces = 0;
for (String key : getProvisionedWifiVifConfigs(ovsdbClient).keySet()) {
if (key.startsWith(ifName)) {
@@ -3100,26 +3099,28 @@ public class OvsdbDao {
}
}
try {
if (numberOfInterfaces >= maxInterfacesPerRadio) {
// this cannot occur, log error, do not try to provision
throw new IllegalStateException(
"Cannot provision more than " + maxInterfacesPerRadio + " interfaces per Wifi Radio");
// this cannot occur, log error, do not try to
// provision
throw new IllegalStateException("Cannot provision more than " + maxInterfacesPerRadio
+ " interfaces per Wifi Radio");
}
if (numberOfInterfaces > 0) {
// 1st interface has no number, 2nd has '_1', 3rd has
// 1st interface has no number, 2nd has '_1', 3rd
// has
// '_2' etc.
ifName = ifName + "_" + numberOfInterfaces;
}
}
configureSingleSsid(ovsdbClient, ifName, ssidConfig.getSsid(), ssidBroadcast, security, freqBand,
ssidConfig.getVlanId(), rrmEnabled, enable80211r, mobilityDomain, enable80211v,
enable80211k, minHwMode, enabled, keyRefresh, uapsdEnabled, apBridge,
ssidConfig.getForwardMode(), gateway, inet, dns, ipAssignScheme, macBlockList,
rateLimitEnable, ssidDlLimit, ssidUlLimit, clientDlLimit, clientUlLimit, rtsCtsThreshold,
fragThresholdBytes, dtimPeriod, captiveMap, walledGardenAllowlist, bonjourServiceMap);
fragThresholdBytes, dtimPeriod, captiveMap, walledGardenAllowlist, bonjourServiceMap,
isUpdate);
} catch (IllegalStateException e) {
// could not provision this SSID, but still can go on

View File

@@ -126,7 +126,7 @@ public class OpensyncGatewayTipWlanOvsdbClientTest {
Mockito.verify(ovsdbSessionMapInterface).getSession("Test_Client_21P10C68818122");
Mockito.verify(ovsdbSession).getOvsdbClient();
Mockito.verify(opensyncExternalIntegrationInterface).getApConfig("Test_Client_21P10C68818122");
Mockito.verify(ovsdbDao).removeAllSsids(ovsdbClient);
Mockito.verify(ovsdbDao).removeAllSsids(ovsdbClient, apConfig);
Mockito.verify(ovsdbDao).removeAllStatsConfigs(ovsdbClient);
Mockito.verify(ovsdbDao).configureWifiRadios(ovsdbClient, apConfig);
Mockito.verify(ovsdbDao).configureSsids(ovsdbClient, apConfig);