OVSDB State Table Changes -- JUnit for RadioState and VIFState table update handling on OpensyncExternalIntegrationCloud

This commit is contained in:
Mike Hansen
2020-07-16 17:53:42 -04:00
parent a833ef18e8
commit b807788b0c
4 changed files with 95 additions and 97 deletions

View File

@@ -2120,6 +2120,53 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
return;
}
for (OpensyncWifiAssociatedClients opensyncWifiAssociatedClients : wifiAssociatedClients) {
com.telecominfraproject.wlan.client.models.Client clientInstance = clientServiceInterface
.getOrNull(customerId, new MacAddress(opensyncWifiAssociatedClients.getMac()));
if (clientInstance == null) {
clientInstance = new com.telecominfraproject.wlan.client.models.Client();
clientInstance.setCustomerId(customerId);
clientInstance.setMacAddress(new MacAddress(opensyncWifiAssociatedClients.getMac()));
clientInstance.setDetails(new ClientInfoDetails());
clientInstance = clientServiceInterface.create(clientInstance);
}
ClientInfoDetails clientDetails = (ClientInfoDetails) clientInstance.getDetails();
clientDetails.setAlias("alias " + clientInstance.getMacAddress().getAddressAsLong());
clientDetails.setApFingerprint("fp " + clientInstance.getMacAddress().getAddressAsString());
clientDetails.setHostName("hostName-" + clientInstance.getMacAddress().getAddressAsLong());
clientDetails.setUserName("user-" + clientInstance.getMacAddress().getAddressAsLong());
clientInstance.setDetails(clientDetails);
clientInstance = clientServiceInterface.update(clientInstance);
LOG.debug("client instance {}", clientInstance);
ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId,
new MacAddress(opensyncWifiAssociatedClients.getMac()));
if (clientSession == null) {
if (clientSession == null) {
LOG.debug("No session found for Client {}, creating new one.",
opensyncWifiAssociatedClients.getMac());
clientSession = new ClientSession();
clientSession.setCustomerId(customerId);
clientSession.setEquipmentId(equipmentId);
clientSession.setMacAddress(new MacAddress(opensyncWifiAssociatedClients.getMac()));
ClientSessionDetails clientSessionDetails = new ClientSessionDetails();
clientSession.setDetails(clientSessionDetails);
clientSession = clientServiceInterface.updateSession(clientSession);
}
}
LOG.debug("client session {}", clientSession);
}
}
@Override

View File

@@ -8,6 +8,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.junit.After;
import org.junit.Before;
@@ -59,7 +60,6 @@ import com.telecominfraproject.wlan.opensync.external.integration.controller.Ope
import com.telecominfraproject.wlan.opensync.external.integration.models.ConnectNodeInfo;
import com.telecominfraproject.wlan.opensync.external.integration.models.OpensyncAPRadioState;
import com.telecominfraproject.wlan.opensync.external.integration.models.OpensyncAPVIFState;
import com.telecominfraproject.wlan.opensync.external.integration.models.OpensyncWifiAssociatedClients;
import com.telecominfraproject.wlan.profile.ProfileServiceInterface;
import com.telecominfraproject.wlan.profile.models.Profile;
import com.telecominfraproject.wlan.profile.network.models.ApNetworkConfiguration;
@@ -73,6 +73,7 @@ import com.telecominfraproject.wlan.status.equipment.report.models.ActiveBSSIDs;
import com.telecominfraproject.wlan.status.equipment.report.models.ClientConnectionDetails;
import com.telecominfraproject.wlan.status.models.Status;
import com.telecominfraproject.wlan.status.models.StatusDataType;
import com.vmware.ovsdb.protocol.operation.notation.Uuid;
import sts.OpensyncStats.Client;
import sts.OpensyncStats.ClientReport;
@@ -348,21 +349,28 @@ public class OpensyncExternalIntegrationCloudTest {
OpensyncAPVIFState vifState1 = new OpensyncAPVIFState();
vifState1.setMac("24:f5:a2:ef:2e:54");
vifState1.setSsid("ssid-1");
OpensyncWifiAssociatedClients wifiClient1 = new OpensyncWifiAssociatedClients();
wifiClient1.setMac("C0:9A:D0:E6:EA:4D");
vifState1.setAssociatedClients(ImmutableList.of(wifiClient1));
// OpensyncWifiAssociatedClients wifiClient1 = new
// OpensyncWifiAssociatedClients();
// wifiClient1.setMac("C0:9A:D0:E6:EA:4D");
Uuid uuid1 = Uuid.of(UUID.randomUUID());
vifState1.setAssociatedClients(ImmutableList.of(uuid1));
OpensyncAPVIFState vifState2 = new OpensyncAPVIFState();
vifState2.setMac("24:f5:a2:ef:2e:55");
vifState2.setSsid("ssid-2");
OpensyncWifiAssociatedClients wifiClient2 = new OpensyncWifiAssociatedClients();
wifiClient2.setMac("7C:AB:60:E6:EA:4D");
vifState2.setAssociatedClients(ImmutableList.of(wifiClient2));
// OpensyncWifiAssociatedClients wifiClient2 = new
// OpensyncWifiAssociatedClients();
// wifiClient2.setMac("7C:AB:60:E6:EA:4D");
Uuid uuid2 = Uuid.of(UUID.randomUUID());
vifState2.setAssociatedClients(ImmutableList.of(uuid2));
OpensyncAPVIFState vifState3 = new OpensyncAPVIFState();
vifState3.setMac("24:f5:a2:ef:2e:56");
vifState3.setSsid("ssid-3");
OpensyncWifiAssociatedClients wifiClient3 = new OpensyncWifiAssociatedClients();
wifiClient3.setMac("C0:9A:D0:76:A9:69");
vifState3.setAssociatedClients(ImmutableList.of(wifiClient3));
// OpensyncWifiAssociatedClients wifiClient3 = new
// OpensyncWifiAssociatedClients();
// wifiClient3.setMac("C0:9A:D0:76:A9:69");
Uuid uuid3 = Uuid.of(UUID.randomUUID());
vifState3.setAssociatedClients(ImmutableList.of(uuid3));
Status bssidStatus = new Status();
bssidStatus.setStatusDataType(StatusDataType.ACTIVE_BSSIDS);
@@ -422,9 +430,9 @@ public class OpensyncExternalIntegrationCloudTest {
OpensyncAPVIFState vifState1 = new OpensyncAPVIFState();
vifState1.setMac("24:f5:a2:ef:2e:54");
vifState1.setSsid("ssid-1");
OpensyncWifiAssociatedClients wifiClient1 = new OpensyncWifiAssociatedClients();
wifiClient1.setMac("C0:9A:D0:E6:EA:4D");
vifState1.setAssociatedClients(ImmutableList.of(wifiClient1));
Uuid uuid1 = Uuid.of(UUID.randomUUID());
vifState1.setAssociatedClients(ImmutableList.of(uuid1));
OpensyncAPRadioState radioState1 = new OpensyncAPRadioState();
radioState1.setChannel(6);
@@ -438,9 +446,9 @@ public class OpensyncExternalIntegrationCloudTest {
OpensyncAPVIFState vifState2 = new OpensyncAPVIFState();
vifState2.setMac("24:f5:a2:ef:2e:55");
vifState2.setSsid("ssid-2");
OpensyncWifiAssociatedClients wifiClient2 = new OpensyncWifiAssociatedClients();
wifiClient2.setMac("7C:AB:60:E6:EA:4D");
vifState2.setAssociatedClients(ImmutableList.of(wifiClient2));
Uuid uuid2 = Uuid.of(UUID.randomUUID());
vifState2.setAssociatedClients(ImmutableList.of(uuid2));
OpensyncAPRadioState radioState2 = new OpensyncAPRadioState();
radioState2.setChannel(36);
@@ -454,9 +462,9 @@ public class OpensyncExternalIntegrationCloudTest {
OpensyncAPVIFState vifState3 = new OpensyncAPVIFState();
vifState3.setMac("24:f5:a2:ef:2e:56");
vifState3.setSsid("ssid-3");
OpensyncWifiAssociatedClients wifiClient3 = new OpensyncWifiAssociatedClients();
wifiClient3.setMac("C0:9A:D0:76:A9:69");
vifState3.setAssociatedClients(ImmutableList.of(wifiClient3));
Uuid uuid3 = Uuid.of(UUID.randomUUID());
vifState3.setAssociatedClients(ImmutableList.of(uuid3));
OpensyncAPRadioState radioState3 = new OpensyncAPRadioState();
radioState3.setChannel(149);

View File

@@ -24,7 +24,7 @@ public class OpensyncAPVIFState extends BaseJsonModel {
public String ssid;
public Map<String, String> security;
public String macList;
public List<OpensyncWifiAssociatedClients> associatedClients;
public List<Uuid> associatedClients;
public boolean enabled;
public int vlanId;
@@ -137,11 +137,11 @@ public class OpensyncAPVIFState extends BaseJsonModel {
this.macList = macList;
}
public List<OpensyncWifiAssociatedClients> getAssociatedClients() {
public List<Uuid> getAssociatedClients() {
return associatedClients;
}
public void setAssociatedClients(List<OpensyncWifiAssociatedClients> list) {
public void setAssociatedClients(List<Uuid> list) {
this.associatedClients = list;
}

View File

@@ -678,7 +678,7 @@ public class OvsdbDao {
Row row = ((SelectResult) result[0]).getRows().iterator().next();
OpensyncAPVIFState tableState = processWifiVIFStateColumn(ovsdbClient, row);
OpensyncAPVIFState tableState = processWifiVIFStateColumn(ovsdbClient, row, false);
vifList.add(tableState);
@@ -686,12 +686,12 @@ public class OvsdbDao {
} catch (Exception e) {
LOG.info("Could not get Wifi_VIF_State for UUID {}. {}", uuid, e.getMessage());
LOG.info("Could not get Wifi_VIF_State for UUID {}. {}", uuid, e);
}
}
private OpensyncAPVIFState processWifiVIFStateColumn(OvsdbClient ovsdbClient, Row row) {
private OpensyncAPVIFState processWifiVIFStateColumn(OvsdbClient ovsdbClient, Row row, boolean update) {
OpensyncAPVIFState tableState = new OpensyncAPVIFState();
Map<String, Value> map = row.getColumns();
@@ -755,18 +755,10 @@ public class OvsdbDao {
tableState.setVifRadioIdx(row.getIntegerColumn("vif_radio_idx").intValue());
}
List<Uuid> associatedClientsList = new ArrayList<>();
Set<Uuid> clients = row.getSetColumn("associated_clients");
List<OpensyncWifiAssociatedClients> associatedClientsList = new ArrayList<>();
if (clients != null) {
for (Uuid client : clients) {
getWifiAssociatedClientByUuid(associatedClientsList, client, ovsdbClient);
LOG.debug("Associated Client Uuid {} UUID {} ", client.toString(), client.getUuid());
}
}
associatedClientsList.addAll(clients);
tableState.setAssociatedClients(associatedClientsList);
@@ -1898,13 +1890,13 @@ public class OvsdbDao {
Row row = rowUpdate.getNew();
if (rowUpdate.getOld() != null) {
LOG.debug("Wifi_VIF_State Columns changed {}", rowUpdate.getOld().getColumns().keySet());
}
if (row != null) {
OpensyncAPVIFState tableState = processWifiVIFStateColumn(ovsdbClient, row);
OpensyncAPVIFState tableState = processWifiVIFStateColumn(ovsdbClient, row,
(rowUpdate.getOld() != null));
LOG.debug("Updated table state {}", tableState.toPrettyString());
@@ -1922,55 +1914,6 @@ public class OvsdbDao {
return ret;
}
public void getWifiAssociatedClientByUuid(List<OpensyncWifiAssociatedClients> associatedClients, Uuid uuid,
OvsdbClient ovsdbClient) {
List<Operation> operations = new ArrayList<>();
List<Condition> conditions = new ArrayList<>();
conditions.add(new Condition("_uuid", Function.EQUALS, new Atom<>(uuid)));
operations.add(new Select(wifiAssociatedClientsDbTable, conditions));
try {
CompletableFuture<OperationResult[]> fResult = ovsdbClient.transact(ovsdbName, operations);
OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS);
if ((result != null) && (result.length > 0) && result[0] instanceof SelectResult
&& !((SelectResult) result[0]).getRows().isEmpty()) {
Row row = ((SelectResult) result[0]).getRows().iterator().next();
OpensyncWifiAssociatedClients tableState = new OpensyncWifiAssociatedClients();
Map<String, Value> map = row.getColumns();
if ((map.get("mac") != null)
&& map.get("mac").getClass().equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) {
tableState.setMac(row.getStringColumn("mac"));
}
if (row.getSetColumn("capabilities") != null) {
tableState.setCapabilities(row.getSetColumn("capabilities"));
}
if ((map.get("state") != null) && map.get("state").getClass()
.equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) {
tableState.setState(row.getStringColumn("state"));
}
if ((map.get("_version") != null) && map.get("_version").getClass()
.equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) {
tableState.setVersion(row.getUuidColumn("_version"));
}
if ((map.get("_uuid") != null) && map.get("_uuid").getClass()
.equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) {
tableState.setVersion(row.getUuidColumn("_uuid"));
}
associatedClients.add(tableState);
}
} catch (Exception e) {
}
}
public List<OpensyncWifiAssociatedClients> getOpensyncWifiAssociatedClients(TableUpdates tableUpdates, String apId,
OvsdbClient ovsdbClient) {
List<OpensyncWifiAssociatedClients> ret = new ArrayList<>();
@@ -2193,11 +2136,11 @@ public class OvsdbDao {
}
}
public void configureSingleSsid(OvsdbClient ovsdbClient, String ifName, String ssid,
boolean ssidBroadcast, Map<String, String> security, String radioFreqBand, int vlanId, boolean rrmEnabled,
boolean enable80211r, String minHwMode, boolean enabled, int keyRefresh, boolean uapsdEnabled,
boolean apBridge, NetworkForwardMode networkForwardMode, String gateway, String inet,
Map<String, String> dns, String ipAssignScheme, Set<String> macBlackList, Set<String> macWhiteList) {
public void configureSingleSsid(OvsdbClient ovsdbClient, String ifName, String ssid, boolean ssidBroadcast,
Map<String, String> security, String radioFreqBand, int vlanId, boolean rrmEnabled, boolean enable80211r,
String minHwMode, boolean enabled, int keyRefresh, boolean uapsdEnabled, boolean apBridge,
NetworkForwardMode networkForwardMode, String gateway, String inet, Map<String, String> dns,
String ipAssignScheme, Set<String> macBlackList, Set<String> macWhiteList) {
List<Operation> operations = new ArrayList<>();
Map<String, Value> updateColumns = new HashMap<>();
@@ -2209,7 +2152,7 @@ public class OvsdbDao {
} else {
updateColumns.put("bridge", new Atom<>("wan"));
}
updateColumns.put("btm", new Atom<>(1));
updateColumns.put("enabled", new Atom<>(enabled));
if (enable80211r) {
@@ -2532,10 +2475,10 @@ public class OvsdbDao {
ifName = ifName + "-" + numberOfInterfaces;
}
configureSingleSsid(ovsdbClient, ifName, ssidConfig.getSsid(),
ssidBroadcast, security, freqBand, ssidConfig.getVlanId(), rrmEnabled, enable80211r,
minHwMode, enabled, keyRefresh, uapsdEnabled, apBridge, ssidConfig.getForwardMode(),
gateway, inet, dns, ipAssignScheme, macBlackList, macWhiteList);
configureSingleSsid(ovsdbClient, ifName, ssidConfig.getSsid(), ssidBroadcast, security, freqBand,
ssidConfig.getVlanId(), rrmEnabled, enable80211r, minHwMode, enabled, keyRefresh,
uapsdEnabled, apBridge, ssidConfig.getForwardMode(), gateway, inet, dns, ipAssignScheme,
macBlackList, macWhiteList);
} catch (IllegalStateException e) {
// could not provision this SSID, but still can go on