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; 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 @Override

View File

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

View File

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

View File

@@ -678,7 +678,7 @@ public class OvsdbDao {
Row row = ((SelectResult) result[0]).getRows().iterator().next(); Row row = ((SelectResult) result[0]).getRows().iterator().next();
OpensyncAPVIFState tableState = processWifiVIFStateColumn(ovsdbClient, row); OpensyncAPVIFState tableState = processWifiVIFStateColumn(ovsdbClient, row, false);
vifList.add(tableState); vifList.add(tableState);
@@ -686,12 +686,12 @@ public class OvsdbDao {
} catch (Exception e) { } 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(); OpensyncAPVIFState tableState = new OpensyncAPVIFState();
Map<String, Value> map = row.getColumns(); Map<String, Value> map = row.getColumns();
@@ -755,18 +755,10 @@ public class OvsdbDao {
tableState.setVifRadioIdx(row.getIntegerColumn("vif_radio_idx").intValue()); tableState.setVifRadioIdx(row.getIntegerColumn("vif_radio_idx").intValue());
} }
List<Uuid> associatedClientsList = new ArrayList<>();
Set<Uuid> clients = row.getSetColumn("associated_clients"); Set<Uuid> clients = row.getSetColumn("associated_clients");
List<OpensyncWifiAssociatedClients> associatedClientsList = new ArrayList<>(); associatedClientsList.addAll(clients);
if (clients != null) {
for (Uuid client : clients) {
getWifiAssociatedClientByUuid(associatedClientsList, client, ovsdbClient);
LOG.debug("Associated Client Uuid {} UUID {} ", client.toString(), client.getUuid());
}
}
tableState.setAssociatedClients(associatedClientsList); tableState.setAssociatedClients(associatedClientsList);
@@ -1898,13 +1890,13 @@ public class OvsdbDao {
Row row = rowUpdate.getNew(); Row row = rowUpdate.getNew();
if (rowUpdate.getOld() != null) { if (rowUpdate.getOld() != null) {
LOG.debug("Wifi_VIF_State Columns changed {}", rowUpdate.getOld().getColumns().keySet()); LOG.debug("Wifi_VIF_State Columns changed {}", rowUpdate.getOld().getColumns().keySet());
} }
if (row != null) { if (row != null) {
OpensyncAPVIFState tableState = processWifiVIFStateColumn(ovsdbClient, row); OpensyncAPVIFState tableState = processWifiVIFStateColumn(ovsdbClient, row,
(rowUpdate.getOld() != null));
LOG.debug("Updated table state {}", tableState.toPrettyString()); LOG.debug("Updated table state {}", tableState.toPrettyString());
@@ -1922,55 +1914,6 @@ public class OvsdbDao {
return ret; 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, public List<OpensyncWifiAssociatedClients> getOpensyncWifiAssociatedClients(TableUpdates tableUpdates, String apId,
OvsdbClient ovsdbClient) { OvsdbClient ovsdbClient) {
List<OpensyncWifiAssociatedClients> ret = new ArrayList<>(); List<OpensyncWifiAssociatedClients> ret = new ArrayList<>();
@@ -2193,11 +2136,11 @@ public class OvsdbDao {
} }
} }
public void configureSingleSsid(OvsdbClient ovsdbClient, String ifName, String ssid, public void configureSingleSsid(OvsdbClient ovsdbClient, String ifName, String ssid, boolean ssidBroadcast,
boolean ssidBroadcast, Map<String, String> security, String radioFreqBand, int vlanId, boolean rrmEnabled, Map<String, String> security, String radioFreqBand, int vlanId, boolean rrmEnabled, boolean enable80211r,
boolean enable80211r, String minHwMode, boolean enabled, int keyRefresh, boolean uapsdEnabled, String minHwMode, boolean enabled, int keyRefresh, boolean uapsdEnabled, boolean apBridge,
boolean apBridge, NetworkForwardMode networkForwardMode, String gateway, String inet, NetworkForwardMode networkForwardMode, String gateway, String inet, Map<String, String> dns,
Map<String, String> dns, String ipAssignScheme, Set<String> macBlackList, Set<String> macWhiteList) { String ipAssignScheme, Set<String> macBlackList, Set<String> macWhiteList) {
List<Operation> operations = new ArrayList<>(); List<Operation> operations = new ArrayList<>();
Map<String, Value> updateColumns = new HashMap<>(); Map<String, Value> updateColumns = new HashMap<>();
@@ -2209,7 +2152,7 @@ public class OvsdbDao {
} else { } else {
updateColumns.put("bridge", new Atom<>("wan")); updateColumns.put("bridge", new Atom<>("wan"));
} }
updateColumns.put("btm", new Atom<>(1)); updateColumns.put("btm", new Atom<>(1));
updateColumns.put("enabled", new Atom<>(enabled)); updateColumns.put("enabled", new Atom<>(enabled));
if (enable80211r) { if (enable80211r) {
@@ -2532,10 +2475,10 @@ public class OvsdbDao {
ifName = ifName + "-" + numberOfInterfaces; ifName = ifName + "-" + numberOfInterfaces;
} }
configureSingleSsid(ovsdbClient, ifName, ssidConfig.getSsid(), configureSingleSsid(ovsdbClient, ifName, ssidConfig.getSsid(), ssidBroadcast, security, freqBand,
ssidBroadcast, security, freqBand, ssidConfig.getVlanId(), rrmEnabled, enable80211r, ssidConfig.getVlanId(), rrmEnabled, enable80211r, minHwMode, enabled, keyRefresh,
minHwMode, enabled, keyRefresh, uapsdEnabled, apBridge, ssidConfig.getForwardMode(), uapsdEnabled, apBridge, ssidConfig.getForwardMode(), gateway, inet, dns, ipAssignScheme,
gateway, inet, dns, ipAssignScheme, macBlackList, macWhiteList); macBlackList, macWhiteList);
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
// could not provision this SSID, but still can go on // could not provision this SSID, but still can go on