diff --git a/opensync-ext-cloud/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationCloud.java b/opensync-ext-cloud/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationCloud.java index 96bd68c..9167148 100644 --- a/opensync-ext-cloud/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationCloud.java +++ b/opensync-ext-cloud/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationCloud.java @@ -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 diff --git a/opensync-ext-cloud/src/test/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationCloudTest.java b/opensync-ext-cloud/src/test/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationCloudTest.java index e404c14..8734d2d 100644 --- a/opensync-ext-cloud/src/test/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationCloudTest.java +++ b/opensync-ext-cloud/src/test/java/com/telecominfraproject/wlan/opensync/external/integration/OpensyncExternalIntegrationCloudTest.java @@ -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); diff --git a/opensync-ext-interface/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/models/OpensyncAPVIFState.java b/opensync-ext-interface/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/models/OpensyncAPVIFState.java index 76615cf..22279f7 100644 --- a/opensync-ext-interface/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/models/OpensyncAPVIFState.java +++ b/opensync-ext-interface/src/main/java/com/telecominfraproject/wlan/opensync/external/integration/models/OpensyncAPVIFState.java @@ -24,7 +24,7 @@ public class OpensyncAPVIFState extends BaseJsonModel { public String ssid; public Map security; public String macList; - public List associatedClients; + public List associatedClients; public boolean enabled; public int vlanId; @@ -137,11 +137,11 @@ public class OpensyncAPVIFState extends BaseJsonModel { this.macList = macList; } - public List getAssociatedClients() { + public List getAssociatedClients() { return associatedClients; } - public void setAssociatedClients(List list) { + public void setAssociatedClients(List list) { this.associatedClients = list; } diff --git a/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbDao.java b/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbDao.java index f20332c..8a14f55 100644 --- a/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbDao.java +++ b/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbDao.java @@ -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 map = row.getColumns(); @@ -755,18 +755,10 @@ public class OvsdbDao { tableState.setVifRadioIdx(row.getIntegerColumn("vif_radio_idx").intValue()); } + List associatedClientsList = new ArrayList<>(); + Set clients = row.getSetColumn("associated_clients"); - List 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 associatedClients, Uuid uuid, - OvsdbClient ovsdbClient) { - - List operations = new ArrayList<>(); - List conditions = new ArrayList<>(); - - conditions.add(new Condition("_uuid", Function.EQUALS, new Atom<>(uuid))); - operations.add(new Select(wifiAssociatedClientsDbTable, conditions)); - - try { - CompletableFuture 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 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 getOpensyncWifiAssociatedClients(TableUpdates tableUpdates, String apId, OvsdbClient ovsdbClient) { List ret = new ArrayList<>(); @@ -2193,11 +2136,11 @@ public class OvsdbDao { } } - public void configureSingleSsid(OvsdbClient ovsdbClient, String ifName, String ssid, - boolean ssidBroadcast, Map 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 dns, String ipAssignScheme, Set macBlackList, Set macWhiteList) { + public void configureSingleSsid(OvsdbClient ovsdbClient, String ifName, String ssid, boolean ssidBroadcast, + Map 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 dns, + String ipAssignScheme, Set macBlackList, Set macWhiteList) { List operations = new ArrayList<>(); Map 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