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 68477cf..a8dd862 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 @@ -65,2535 +65,2495 @@ import com.vmware.ovsdb.service.OvsdbClient; @Component public class OvsdbDao { - private static final Logger LOG = LoggerFactory.getLogger(OvsdbDao.class); + private static final Logger LOG = LoggerFactory.getLogger(OvsdbDao.class); - @org.springframework.beans.factory.annotation.Value("${connectus.ovsdb.managerAddr:3.88.149.10}") - private String managerIpAddr; - - @org.springframework.beans.factory.annotation.Value("${connectus.ovsdb.listenPort:6640}") - private int ovsdbListenPort; - - @org.springframework.beans.factory.annotation.Value("${connectus.mqttBroker.address:testportal.123wlan.com}") - private String mqttBrokerAddress; - - @org.springframework.beans.factory.annotation.Value("${connectus.mqttBroker.listenPort:1883}") - private int mqttBrokerListenPort; - - @org.springframework.beans.factory.annotation.Value("${connectus.ovsdb.timeoutSec:30}") - private int ovsdbTimeoutSec; - - @org.springframework.beans.factory.annotation.Value("${connectus.ovsdb.wifi-iface.default_bridge:br-home}") - public String bridgeNameVifInterfaces; - - @org.springframework.beans.factory.annotation.Value("${connectus.ovsdb.wifi-iface.default_radio1:home-ap-24}") - public String ifName2pt4GHz; - @org.springframework.beans.factory.annotation.Value("${connectus.ovsdb.wifi-iface.default_radio2:home-ap-l50}") - public String ifName5GHzL; - @org.springframework.beans.factory.annotation.Value("${connectus.ovsdb.wifi-iface.default_radio0:home-ap-u50}") - public String ifName5GHzU; - - @org.springframework.beans.factory.annotation.Value("${connectus.ovsdb.wifi-device.radio0:wifi2}") - public String radioName5GHzU; - @org.springframework.beans.factory.annotation.Value("${connectus.ovsdb.wifi-device.radio2:wifi1}") - public String radioName5GHzL; - @org.springframework.beans.factory.annotation.Value("${connectus.ovsdb.wifi-device.radio1:wifi0}") - public String radioName2pt4GHz; - - public static final String ovsdbName = "Open_vSwitch"; - public static final String awlanNodeDbTable = "AWLAN_Node"; - public static final String wifiStatsConfigDbTable = "Wifi_Stats_Config"; - - public static final String interfaceDbTable = "Interface"; - public static final String portDbTable = "Port"; - public static final String bridgeDbTable = "Bridge"; - - public static final String wifiRadioConfigDbTable = "Wifi_Radio_Config"; - public static final String wifiRadioStateDbTable = "Wifi_Radio_State"; - - public static final String wifiVifConfigDbTable = "Wifi_VIF_Config"; - public static final String wifiVifStateDbTable = "Wifi_VIF_State"; - - public static final String wifiInetConfigDbTable = "Wifi_Inet_Config"; - public static final String wifiInetStateDbTable = "Wifi_Inet_State"; - - public static final String wifiAssociatedClientsDbTable = "Wifi_Associated_Clients"; - - public ConnectNodeInfo getConnectNodeInfo(OvsdbClient ovsdbClient) { - ConnectNodeInfo ret = new ConnectNodeInfo(); - - try { - List operations = new ArrayList<>(); - List conditions = new ArrayList<>(); - List columns = new ArrayList<>(); - columns.add("mqtt_settings"); - columns.add("redirector_addr"); - columns.add("manager_addr"); - columns.add("sku_number"); - columns.add("serial_number"); - columns.add("model"); - columns.add("firmware_version"); - columns.add("platform_version"); - columns.add("revision"); - - operations.add(new Select(awlanNodeDbTable, conditions, columns)); - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - - if (LOG.isDebugEnabled()) { - LOG.debug("Select from {}:", awlanNodeDbTable); - - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - } - } - - Row row = null; - if (result != null && result.length > 0 && !((SelectResult) result[0]).getRows().isEmpty()) { - row = ((SelectResult) result[0]).getRows().iterator().next(); - } - - ret.mqttSettings = row != null ? row.getMapColumn("mqtt_settings") : null; - ret.redirectorAddr = row != null ? row.getStringColumn("redirector_addr") : null; - ret.managerAddr = row != null ? row.getStringColumn("manager_addr") : null; - - ret.platformVersion = row != null ? row.getStringColumn("platform_version") : null; - ret.firmwareVersion = row != null ? row.getStringColumn("firmware_version") : null; - - ret.revision = row != null ? row.getStringColumn("revision") : null; - - ret.skuNumber = getSingleValueFromSet(row, "sku_number"); - ret.serialNumber = getSingleValueFromSet(row, "serial_number"); - ret.model = getSingleValueFromSet(row, "model"); - - // now populate macAddress, ipV4Address from Wifi_Inet_State - // first look them up for if_name = br-wan - fillInIpAddressAndMac(ovsdbClient, ret, "br-wan"); - if (ret.ipV4Address == null || ret.macAddress == null) { - // when not found - look them up for if_name = br-lan - fillInIpAddressAndMac(ovsdbClient, ret, "br-lan"); - } - - } - catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { - throw new RuntimeException(e); - } - - return ret; - } - - public void fillInIpAddressAndMac(OvsdbClient ovsdbClient, ConnectNodeInfo connectNodeInfo, String ifName) { - try { - List operations = new ArrayList<>(); - List conditions = new ArrayList<>(); - List columns = new ArrayList<>(); - // populate macAddress, ipV4Address from Wifi_Inet_State - - columns.add("inet_addr"); - columns.add("hwaddr"); - - conditions.add(new Condition("if_name", Function.EQUALS, new Atom<>(ifName))); - - operations.add(new Select(wifiInetStateDbTable, conditions, columns)); - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - - if (LOG.isDebugEnabled()) { - LOG.debug("Select from {}:", wifiInetStateDbTable); - - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - } - } - - Row row = null; - if (result != null && result.length > 0 && !((SelectResult) result[0]).getRows().isEmpty()) { - row = ((SelectResult) result[0]).getRows().iterator().next(); - connectNodeInfo.ipV4Address = getSingleValueFromSet(row, "inet_addr"); - connectNodeInfo.macAddress = row.getStringColumn("hwaddr"); - } - - } - catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { - throw new RuntimeException(e); - } - - } - - public ConnectNodeInfo updateConnectNodeInfoOnConnect(OvsdbClient ovsdbClient, String clientCn, - ConnectNodeInfo incomingConnectNodeInfo) { - ConnectNodeInfo ret = incomingConnectNodeInfo.clone(); - - try { - List operations = new ArrayList<>(); - Map updateColumns = new HashMap<>(); - - // set device_mode = cloud - plume's APs do not use it - // updateColumns.put("device_mode", new Atom("cloud") ); - - // update sku_number if it was empty - if (ret.skuNumber == null || ret.skuNumber.isEmpty()) { - ret.skuNumber = "connectus.ai_" + ret.serialNumber; - updateColumns.put("sku_number", new Atom<>(ret.skuNumber)); - } - - // Configure the MQTT connection - // ovsh u AWLAN_Node - // mqtt_settings:ins:'["map",[["broker","testportal.123wlan.com"],["topics","/ap/dev-ap-0300/opensync"],["qos","0"],["port","1883"],["remote_log","1"]]]' - Map newMqttSettings = new HashMap<>(); - newMqttSettings.put("broker", mqttBrokerAddress); - newMqttSettings.put("topics", "/ap/" + clientCn + "_" + ret.serialNumber + "/opensync"); - newMqttSettings.put("port", "" + mqttBrokerListenPort); - newMqttSettings.put("compress", "zlib"); - newMqttSettings.put("qos", "0"); - newMqttSettings.put("remote_log", "1"); - - if (ret.mqttSettings == null || !ret.mqttSettings.equals(newMqttSettings)) { - @SuppressWarnings("unchecked") - com.vmware.ovsdb.protocol.operation.notation.Map mgttSettings = com.vmware.ovsdb.protocol.operation.notation.Map - .of(newMqttSettings); - ret.mqttSettings = newMqttSettings; - updateColumns.put("mqtt_settings", mgttSettings); - } - - if (!updateColumns.isEmpty()) { - Row row = new Row(updateColumns); - operations.add(new Update(awlanNodeDbTable, row)); - - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - - if (LOG.isDebugEnabled()) { - LOG.debug("Updated {}:", awlanNodeDbTable); - - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - } - } - } - - } - catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { - throw new RuntimeException(e); - } - - return ret; - } - - /** - * @param ovsdbClient - * @return value of reporting_interval column for the stats_type=device from - * the Wifi_Stats_Config table. If value is not provisioned then - * return -1. - */ - public long getDeviceStatsReportingInterval(OvsdbClient ovsdbClient) { - long ret = -1; - try { - List operations = new ArrayList<>(); - List conditions = new ArrayList<>(); - List columns = new ArrayList<>(); - - columns.add("reporting_interval"); - columns.add("stats_type"); - columns.add("radio_type"); - - conditions.add(new Condition("stats_type", Function.EQUALS, new Atom<>("device"))); - - operations.add(new Select(wifiStatsConfigDbTable, conditions, columns)); - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - - if (LOG.isDebugEnabled()) { - LOG.debug("Select from {}:", wifiStatsConfigDbTable); - - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - } - } - - Row row = null; - if (result != null && result.length > 0 && !((SelectResult) result[0]).getRows().isEmpty()) { - row = ((SelectResult) result[0]).getRows().iterator().next(); - ret = row.getIntegerColumn("reporting_interval"); - LOG.info("Stats collection for stats_type=device is already configured with reporting_interval = {}", - ret); - } - - } - catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { - throw new RuntimeException(e); - } - - return ret; - } - - /** - * @param ovsdbClient - * @param value - * of reporting_interval column for the stats_type=device from - * the Wifi_Stats_Config table. If value is not provisioned then - * return -1. - */ - public void updateDeviceStatsReportingInterval(OvsdbClient ovsdbClient, long newValue) { - try { - List operations = new ArrayList<>(); - Map updateColumns = new HashMap<>(); - - // turn on stats collection over MQTT: (reporting_interval is in - // seconds?) - // $ ovsh i Wifi_Stats_Config reporting_interval:=10 - // radio_type:="2.4G" stats_type:="device" - - updateColumns.put("reporting_interval", new Atom<>(10)); - updateColumns.put("radio_type", new Atom<>("2.4G")); - updateColumns.put("stats_type", new Atom<>("device")); - - Row row = new Row(updateColumns); - operations.add(new Insert(wifiStatsConfigDbTable, row)); - - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + @org.springframework.beans.factory.annotation.Value("${connectus.ovsdb.managerAddr:3.88.149.10}") + private String managerIpAddr; + + @org.springframework.beans.factory.annotation.Value("${connectus.ovsdb.listenPort:6640}") + private int ovsdbListenPort; + + @org.springframework.beans.factory.annotation.Value("${connectus.mqttBroker.address:testportal.123wlan.com}") + private String mqttBrokerAddress; + + @org.springframework.beans.factory.annotation.Value("${connectus.mqttBroker.listenPort:1883}") + private int mqttBrokerListenPort; + + @org.springframework.beans.factory.annotation.Value("${connectus.ovsdb.timeoutSec:30}") + private int ovsdbTimeoutSec; + + @org.springframework.beans.factory.annotation.Value("${connectus.ovsdb.wifi-iface.default_bridge:br-home}") + public String bridgeNameVifInterfaces; + + @org.springframework.beans.factory.annotation.Value("${connectus.ovsdb.wifi-iface.default_radio1:home-ap-24}") + public String ifName2pt4GHz; + @org.springframework.beans.factory.annotation.Value("${connectus.ovsdb.wifi-iface.default_radio2:home-ap-l50}") + public String ifName5GHzL; + @org.springframework.beans.factory.annotation.Value("${connectus.ovsdb.wifi-iface.default_radio0:home-ap-u50}") + public String ifName5GHzU; - if (LOG.isDebugEnabled()) { - LOG.debug("Updated {}:", wifiStatsConfigDbTable); + @org.springframework.beans.factory.annotation.Value("${connectus.ovsdb.wifi-device.radio0:wifi2}") + public String radioName5GHzU; + @org.springframework.beans.factory.annotation.Value("${connectus.ovsdb.wifi-device.radio2:wifi1}") + public String radioName5GHzL; + @org.springframework.beans.factory.annotation.Value("${connectus.ovsdb.wifi-device.radio1:wifi0}") + public String radioName2pt4GHz; - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - } - } - - } - catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { - throw new RuntimeException(e); - } - - } - - public void performRedirect(OvsdbClient ovsdbClient, String clientCn) { - - List operations = new ArrayList<>(); - List conditions = new ArrayList<>(); - List columns = new ArrayList<>(); - columns.add("manager_addr"); - columns.add("sku_number"); - columns.add("serial_number"); - columns.add("model"); - columns.add("firmware_version"); - - try { - LOG.debug("Starting Redirect"); - - operations.add(new Select(awlanNodeDbTable, conditions, columns)); - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - - LOG.debug("Select from AWLAN_Node:"); + public static final String ovsdbName = "Open_vSwitch"; + public static final String awlanNodeDbTable = "AWLAN_Node"; + public static final String wifiStatsConfigDbTable = "Wifi_Stats_Config"; + + public static final String interfaceDbTable = "Interface"; + public static final String portDbTable = "Port"; + public static final String bridgeDbTable = "Bridge"; + + public static final String wifiRadioConfigDbTable = "Wifi_Radio_Config"; + public static final String wifiRadioStateDbTable = "Wifi_Radio_State"; + + public static final String wifiVifConfigDbTable = "Wifi_VIF_Config"; + public static final String wifiVifStateDbTable = "Wifi_VIF_State"; + + public static final String wifiInetConfigDbTable = "Wifi_Inet_Config"; + public static final String wifiInetStateDbTable = "Wifi_Inet_State"; + + public static final String wifiAssociatedClientsDbTable = "Wifi_Associated_Clients"; + + public ConnectNodeInfo getConnectNodeInfo(OvsdbClient ovsdbClient) { + ConnectNodeInfo ret = new ConnectNodeInfo(); + + try { + List operations = new ArrayList<>(); + List conditions = new ArrayList<>(); + List columns = new ArrayList<>(); + columns.add("mqtt_settings"); + columns.add("redirector_addr"); + columns.add("manager_addr"); + columns.add("sku_number"); + columns.add("serial_number"); + columns.add("model"); + columns.add("firmware_version"); + columns.add("platform_version"); + columns.add("revision"); + + operations.add(new Select(awlanNodeDbTable, conditions, columns)); + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + + if (LOG.isDebugEnabled()) { + LOG.debug("Select from {}:", awlanNodeDbTable); + + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + } + } + + Row row = null; + if (result != null && result.length > 0 && !((SelectResult) result[0]).getRows().isEmpty()) { + row = ((SelectResult) result[0]).getRows().iterator().next(); + } + + ret.mqttSettings = row != null ? row.getMapColumn("mqtt_settings") : null; + ret.redirectorAddr = row != null ? row.getStringColumn("redirector_addr") : null; + ret.managerAddr = row != null ? row.getStringColumn("manager_addr") : null; + + ret.platformVersion = row != null ? row.getStringColumn("platform_version") : null; + ret.firmwareVersion = row != null ? row.getStringColumn("firmware_version") : null; + + ret.revision = row != null ? row.getStringColumn("revision") : null; + + ret.skuNumber = getSingleValueFromSet(row, "sku_number"); + ret.serialNumber = getSingleValueFromSet(row, "serial_number"); + ret.model = getSingleValueFromSet(row, "model"); + + // now populate macAddress, ipV4Address from Wifi_Inet_State + // first look them up for if_name = br-wan + fillInIpAddressAndMac(ovsdbClient, ret, "br-wan"); + if (ret.ipV4Address == null || ret.macAddress == null) { + // when not found - look them up for if_name = br-lan + fillInIpAddressAndMac(ovsdbClient, ret, "br-lan"); + } + + } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { + throw new RuntimeException(e); + } + + return ret; + } + + public void fillInIpAddressAndMac(OvsdbClient ovsdbClient, ConnectNodeInfo connectNodeInfo, String ifName) { + try { + List operations = new ArrayList<>(); + List conditions = new ArrayList<>(); + List columns = new ArrayList<>(); + // populate macAddress, ipV4Address from Wifi_Inet_State + + columns.add("inet_addr"); + columns.add("hwaddr"); + + conditions.add(new Condition("if_name", Function.EQUALS, new Atom<>(ifName))); + + operations.add(new Select(wifiInetStateDbTable, conditions, columns)); + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + + if (LOG.isDebugEnabled()) { + LOG.debug("Select from {}:", wifiInetStateDbTable); + + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + } + } + + Row row = null; + if (result != null && result.length > 0 && !((SelectResult) result[0]).getRows().isEmpty()) { + row = ((SelectResult) result[0]).getRows().iterator().next(); + connectNodeInfo.ipV4Address = getSingleValueFromSet(row, "inet_addr"); + connectNodeInfo.macAddress = row.getStringColumn("hwaddr"); + } + + } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { + throw new RuntimeException(e); + } + + } + + public ConnectNodeInfo updateConnectNodeInfoOnConnect(OvsdbClient ovsdbClient, String clientCn, + ConnectNodeInfo incomingConnectNodeInfo) { + ConnectNodeInfo ret = incomingConnectNodeInfo.clone(); + + try { + List operations = new ArrayList<>(); + Map updateColumns = new HashMap<>(); + + // set device_mode = cloud - plume's APs do not use it + // updateColumns.put("device_mode", new Atom("cloud") ); + + // update sku_number if it was empty + if (ret.skuNumber == null || ret.skuNumber.isEmpty()) { + ret.skuNumber = "connectus.ai_" + ret.serialNumber; + updateColumns.put("sku_number", new Atom<>(ret.skuNumber)); + } + + // Configure the MQTT connection + // ovsh u AWLAN_Node + // mqtt_settings:ins:'["map",[["broker","testportal.123wlan.com"],["topics","/ap/dev-ap-0300/opensync"],["qos","0"],["port","1883"],["remote_log","1"]]]' + Map newMqttSettings = new HashMap<>(); + newMqttSettings.put("broker", mqttBrokerAddress); + newMqttSettings.put("topics", "/ap/" + clientCn + "_" + ret.serialNumber + "/opensync"); + newMqttSettings.put("port", "" + mqttBrokerListenPort); + newMqttSettings.put("compress", "zlib"); + newMqttSettings.put("qos", "0"); + newMqttSettings.put("remote_log", "1"); + + if (ret.mqttSettings == null || !ret.mqttSettings.equals(newMqttSettings)) { + @SuppressWarnings("unchecked") + com.vmware.ovsdb.protocol.operation.notation.Map mgttSettings = com.vmware.ovsdb.protocol.operation.notation.Map + .of(newMqttSettings); + ret.mqttSettings = newMqttSettings; + updateColumns.put("mqtt_settings", mgttSettings); + } + + if (!updateColumns.isEmpty()) { + Row row = new Row(updateColumns); + operations.add(new Update(awlanNodeDbTable, row)); + + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + + if (LOG.isDebugEnabled()) { + LOG.debug("Updated {}:", awlanNodeDbTable); + + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + } + } + } + + } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { + throw new RuntimeException(e); + } + + return ret; + } + + /** + * @param ovsdbClient + * @return value of reporting_interval column for the stats_type=device from the + * Wifi_Stats_Config table. If value is not provisioned then return -1. + */ + public long getDeviceStatsReportingInterval(OvsdbClient ovsdbClient) { + long ret = -1; + try { + List operations = new ArrayList<>(); + List conditions = new ArrayList<>(); + List columns = new ArrayList<>(); + + columns.add("reporting_interval"); + columns.add("stats_type"); + columns.add("radio_type"); + + conditions.add(new Condition("stats_type", Function.EQUALS, new Atom<>("device"))); + + operations.add(new Select(wifiStatsConfigDbTable, conditions, columns)); + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + + if (LOG.isDebugEnabled()) { + LOG.debug("Select from {}:", wifiStatsConfigDbTable); + + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + } + } + + Row row = null; + if (result != null && result.length > 0 && !((SelectResult) result[0]).getRows().isEmpty()) { + row = ((SelectResult) result[0]).getRows().iterator().next(); + ret = row.getIntegerColumn("reporting_interval"); + LOG.info("Stats collection for stats_type=device is already configured with reporting_interval = {}", + ret); + } + + } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { + throw new RuntimeException(e); + } + + return ret; + } + + /** + * @param ovsdbClient + * @param value of reporting_interval column for the stats_type=device + * from the Wifi_Stats_Config table. If value is not + * provisioned then return -1. + */ + public void updateDeviceStatsReportingInterval(OvsdbClient ovsdbClient, long newValue) { + try { + List operations = new ArrayList<>(); + Map updateColumns = new HashMap<>(); + + // turn on stats collection over MQTT: (reporting_interval is in + // seconds?) + // $ ovsh i Wifi_Stats_Config reporting_interval:=10 + // radio_type:="2.4G" stats_type:="device" + + updateColumns.put("reporting_interval", new Atom<>(10)); + updateColumns.put("radio_type", new Atom<>("2.4G")); + updateColumns.put("stats_type", new Atom<>("device")); + + Row row = new Row(updateColumns); + operations.add(new Insert(wifiStatsConfigDbTable, row)); - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - } + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - String skuNumber = null; - String serialNumber = null; - String model = null; - String firmwareVersion = null; + if (LOG.isDebugEnabled()) { + LOG.debug("Updated {}:", wifiStatsConfigDbTable); - Row row = null; - if (result != null && result.length > 0 && !((SelectResult) result[0]).getRows().isEmpty()) { - row = ((SelectResult) result[0]).getRows().iterator().next(); - } + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + } + } - firmwareVersion = row != null ? row.getStringColumn("firmware_version") : null; + } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { + throw new RuntimeException(e); + } + + } + + public void performRedirect(OvsdbClient ovsdbClient, String clientCn) { + + List operations = new ArrayList<>(); + List conditions = new ArrayList<>(); + List columns = new ArrayList<>(); + columns.add("manager_addr"); + columns.add("sku_number"); + columns.add("serial_number"); + columns.add("model"); + columns.add("firmware_version"); - skuNumber = getSingleValueFromSet(row, "sku_number"); - serialNumber = getSingleValueFromSet(row, "serial_number"); - model = getSingleValueFromSet(row, "model"); + try { + LOG.debug("Starting Redirect"); - LOG.info("Redirecting AP Node: clientCn {} serialNumber {} model {} firmwareVersion {} skuNumber {}", - clientCn, serialNumber, model, firmwareVersion, skuNumber); + operations.add(new Select(awlanNodeDbTable, conditions, columns)); + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - // Update table AWLAN_Node - set manager_addr - operations.clear(); - Map updateColumns = new HashMap<>(); + LOG.debug("Select from AWLAN_Node:"); - updateColumns.put("manager_addr", new Atom<>("ssl:" + managerIpAddr + ":" + ovsdbListenPort)); + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + } - row = new Row(updateColumns); - operations.add(new Update(awlanNodeDbTable, row)); + String skuNumber = null; + String serialNumber = null; + String model = null; + String firmwareVersion = null; - fResult = ovsdbClient.transact(ovsdbName, operations); - result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + Row row = null; + if (result != null && result.length > 0 && !((SelectResult) result[0]).getRows().isEmpty()) { + row = ((SelectResult) result[0]).getRows().iterator().next(); + } - LOG.debug("Updated AWLAN_Node:"); + firmwareVersion = row != null ? row.getStringColumn("firmware_version") : null; - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - } + skuNumber = getSingleValueFromSet(row, "sku_number"); + serialNumber = getSingleValueFromSet(row, "serial_number"); + model = getSingleValueFromSet(row, "model"); - LOG.debug("Redirect Done"); - } - catch (ExecutionException | InterruptedException | OvsdbClientException | TimeoutException e) { - LOG.error("Error when redirecting AP Node", e); - throw new RuntimeException(e); - } + LOG.info("Redirecting AP Node: clientCn {} serialNumber {} model {} firmwareVersion {} skuNumber {}", + clientCn, serialNumber, model, firmwareVersion, skuNumber); - } + // Update table AWLAN_Node - set manager_addr + operations.clear(); + Map updateColumns = new HashMap<>(); - public Set getSet(Row row, String columnName) { + updateColumns.put("manager_addr", new Atom<>("ssl:" + managerIpAddr + ":" + ovsdbListenPort)); - Set set = row != null ? row.getSetColumn(columnName) : null; + row = new Row(updateColumns); + operations.add(new Update(awlanNodeDbTable, row)); - return set; - } + fResult = ovsdbClient.transact(ovsdbName, operations); + result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - public T getSingleValueFromSet(Row row, String columnName) { + LOG.debug("Updated AWLAN_Node:"); - Set set = row != null ? row.getSetColumn(columnName) : null; - T ret = set != null && !set.isEmpty() ? set.iterator().next() : null; + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + } - return ret; - } + LOG.debug("Redirect Done"); + } catch (ExecutionException | InterruptedException | OvsdbClientException | TimeoutException e) { + LOG.error("Error when redirecting AP Node", e); + throw new RuntimeException(e); + } - public Map getProvisionedInterfaces(OvsdbClient ovsdbClient) { - Map ret = new HashMap<>(); + } - List operations = new ArrayList<>(); - List conditions = new ArrayList<>(); - List columns = new ArrayList<>(); - columns.add("name"); - columns.add("type"); - columns.add("options"); - columns.add("_uuid"); - columns.add("ofport"); - columns.add("mtu"); - columns.add("ifindex"); - columns.add("link_state"); - columns.add("admin_state"); + public Set getSet(Row row, String columnName) { - try { - LOG.debug("Retrieving Interfaces:"); + Set set = row != null ? row.getSetColumn(columnName) : null; - operations.add(new Select(interfaceDbTable, conditions, columns)); - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + return set; + } - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - } + public T getSingleValueFromSet(Row row, String columnName) { - for (Row row : ((SelectResult) result[0]).getRows()) { + Set set = row != null ? row.getSetColumn(columnName) : null; + T ret = set != null && !set.isEmpty() ? set.iterator().next() : null; - InterfaceInfo interfaceInfo = new InterfaceInfo(); - interfaceInfo.name = row.getStringColumn("name"); - interfaceInfo.type = row.getStringColumn("type"); - interfaceInfo.uuid = row.getUuidColumn("_uuid"); + return ret; + } - Long tmp = getSingleValueFromSet(row, "ofport"); - interfaceInfo.ofport = tmp != null ? tmp.intValue() : 0; + public Map getProvisionedInterfaces(OvsdbClient ovsdbClient) { + Map ret = new HashMap<>(); - tmp = getSingleValueFromSet(row, "mtu"); - interfaceInfo.mtu = tmp != null ? tmp.intValue() : 0; + List operations = new ArrayList<>(); + List conditions = new ArrayList<>(); + List columns = new ArrayList<>(); + columns.add("name"); + columns.add("type"); + columns.add("options"); + columns.add("_uuid"); + columns.add("ofport"); + columns.add("mtu"); + columns.add("ifindex"); + columns.add("link_state"); + columns.add("admin_state"); - tmp = getSingleValueFromSet(row, "ifindex"); - interfaceInfo.ifIndex = tmp != null ? tmp.intValue() : 0; + try { + LOG.debug("Retrieving Interfaces:"); - String tmpStr = getSingleValueFromSet(row, "link_state"); - interfaceInfo.linkState = tmpStr != null ? tmpStr : ""; + operations.add(new Select(interfaceDbTable, conditions, columns)); + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - tmpStr = getSingleValueFromSet(row, "admin_state"); - interfaceInfo.adminState = tmpStr != null ? tmpStr : ""; + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + } - interfaceInfo.options = row.getMapColumn("options"); + for (Row row : ((SelectResult) result[0]).getRows()) { - ret.put(interfaceInfo.name, interfaceInfo); - } + InterfaceInfo interfaceInfo = new InterfaceInfo(); + interfaceInfo.name = row.getStringColumn("name"); + interfaceInfo.type = row.getStringColumn("type"); + interfaceInfo.uuid = row.getUuidColumn("_uuid"); - LOG.debug("Retrieved Interfaces: {}", ret); + Long tmp = getSingleValueFromSet(row, "ofport"); + interfaceInfo.ofport = tmp != null ? tmp.intValue() : 0; - } - catch (ExecutionException | InterruptedException | OvsdbClientException | TimeoutException e) { - LOG.error("Error in getProvisionedInterfaces", e); + tmp = getSingleValueFromSet(row, "mtu"); + interfaceInfo.mtu = tmp != null ? tmp.intValue() : 0; - throw new RuntimeException(e); - } + tmp = getSingleValueFromSet(row, "ifindex"); + interfaceInfo.ifIndex = tmp != null ? tmp.intValue() : 0; - return ret; - } + String tmpStr = getSingleValueFromSet(row, "link_state"); + interfaceInfo.linkState = tmpStr != null ? tmpStr : ""; - public Map getProvisionedPorts(OvsdbClient ovsdbClient) { - Map ret = new HashMap<>(); + tmpStr = getSingleValueFromSet(row, "admin_state"); + interfaceInfo.adminState = tmpStr != null ? tmpStr : ""; - List operations = new ArrayList<>(); - List conditions = new ArrayList<>(); - List columns = new ArrayList<>(); - columns.add("name"); - columns.add("_uuid"); - columns.add("interfaces"); + interfaceInfo.options = row.getMapColumn("options"); - try { - LOG.debug("Retrieving Ports:"); + ret.put(interfaceInfo.name, interfaceInfo); + } - operations.add(new Select(portDbTable, conditions, columns)); - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + LOG.debug("Retrieved Interfaces: {}", ret); - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - } + } catch (ExecutionException | InterruptedException | OvsdbClientException | TimeoutException e) { + LOG.error("Error in getProvisionedInterfaces", e); - for (Row row : ((SelectResult) result[0]).getRows()) { + throw new RuntimeException(e); + } - PortInfo portInfo = new PortInfo(); - portInfo.name = row.getStringColumn("name"); - portInfo.uuid = row.getUuidColumn("_uuid"); - portInfo.interfaceUuids = row.getSetColumn("interfaces"); + return ret; + } - 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 getProvisionedBridges(OvsdbClient ovsdbClient) { - Map ret = new HashMap<>(); - - List operations = new ArrayList<>(); - List conditions = new ArrayList<>(); - List 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 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 getProvisionedWifiRadioConfigs(OvsdbClient ovsdbClient) { - Map ret = new HashMap<>(); - - List operations = new ArrayList<>(); - List conditions = new ArrayList<>(); - List columns = new ArrayList<>(); - - columns.add("_uuid"); - columns.add("if_name"); - columns.add("bcn_int"); - columns.add("channel"); - columns.add("channel_mode"); - columns.add("country"); - columns.add("enabled"); - columns.add("ht_mode"); - columns.add("tx_power"); - columns.add("vif_configs"); - columns.add("freq_band"); - columns.add("hw_config"); - columns.add("hw_type"); - - try { - LOG.debug("Retrieving WifiRadioConfig:"); - - operations.add(new Select(wifiRadioConfigDbTable, conditions, columns)); - CompletableFuture 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()) { - - WifiRadioConfigInfo wifiRadioConfigInfo = new WifiRadioConfigInfo(); - wifiRadioConfigInfo.uuid = row.getUuidColumn("_uuid"); - wifiRadioConfigInfo.ifName = row.getStringColumn("if_name"); - Long beaconTmp = getSingleValueFromSet(row, "bcn_int"); - if (beaconTmp == null) { - beaconTmp = 0L; - } - wifiRadioConfigInfo.beaconInterval = beaconTmp.intValue(); - Long channelTmp = getSingleValueFromSet(row, "channel"); - if (channelTmp == null) { - channelTmp = -1L; - } - wifiRadioConfigInfo.channel = channelTmp.intValue(); - wifiRadioConfigInfo.channelMode = getSingleValueFromSet(row, "channel_mode"); - wifiRadioConfigInfo.country = getSingleValueFromSet(row, "country"); - Boolean tmp = getSingleValueFromSet(row, "enabled"); - wifiRadioConfigInfo.enabled = tmp != null ? tmp : false; - wifiRadioConfigInfo.htMode = getSingleValueFromSet(row, "ht_mode"); - wifiRadioConfigInfo.txPower = getSingleValueFromSet(row, "txPower"); - wifiRadioConfigInfo.vifConfigUuids = row.getSetColumn("vif_configs"); - wifiRadioConfigInfo.freqBand = row.getStringColumn("freq_band"); - wifiRadioConfigInfo.hwConfig = row.getMapColumn("hw_config"); - wifiRadioConfigInfo.hwType = row.getStringColumn("hw_type"); - ret.put(wifiRadioConfigInfo.ifName, wifiRadioConfigInfo); - } - - LOG.debug("Retrieved WifiRadioConfig: {}", ret); - - } - catch (ExecutionException | InterruptedException | OvsdbClientException | TimeoutException e) { - LOG.error("Error in getProvisionedWifiRadioConfigs", e); - throw new RuntimeException(e); - } - - return ret; - } - - public Map getProvisionedWifiVifConfigs(OvsdbClient ovsdbClient) { - Map ret = new HashMap<>(); - - List operations = new ArrayList<>(); - List conditions = new ArrayList<>(); - List columns = new ArrayList<>(); - columns.add("bridge"); - columns.add("ap_bridge"); - columns.add("_uuid"); - columns.add("btm"); - columns.add("enabled"); - columns.add("ft_psk"); - columns.add("group_rekey"); - columns.add("if_name"); - columns.add("min_hw_mode"); - columns.add("mode"); - columns.add("rrm"); - columns.add("ssid"); - columns.add("ssid_broadcast"); - columns.add("uapsd_enable"); - columns.add("vif_radio_idx"); - columns.add("security"); - columns.add("vlan_id"); - - try { - LOG.debug("Retrieving WifiVifConfig:"); - - operations.add(new Select(wifiVifConfigDbTable, conditions, columns)); - CompletableFuture 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()) { - - WifiVifConfigInfo wifiVifConfigInfo = new WifiVifConfigInfo(); - wifiVifConfigInfo.bridge = row.getStringColumn("bridge"); - wifiVifConfigInfo.apBridge = row.getBooleanColumn("ap_bridge"); - wifiVifConfigInfo.uuid = row.getUuidColumn("_uuid"); - wifiVifConfigInfo.btm = row.getIntegerColumn("btm").intValue(); - wifiVifConfigInfo.enabled = row.getBooleanColumn("enabled"); - wifiVifConfigInfo.ftPsk = row.getIntegerColumn("ft_psk").intValue(); - wifiVifConfigInfo.groupRekey = row.getIntegerColumn("group_rekey").intValue(); - wifiVifConfigInfo.minHwMode = row.getStringColumn("min_hw_mode"); - wifiVifConfigInfo.ifName = row.getStringColumn("if_name"); - wifiVifConfigInfo.mode = row.getStringColumn("mode"); - wifiVifConfigInfo.rrm = row.getIntegerColumn("rrm").intValue(); - wifiVifConfigInfo.ssid = row.getStringColumn("ssid"); - wifiVifConfigInfo.ssidBroadcast = row.getStringColumn("ssid_broadcast"); - wifiVifConfigInfo.uapsdEnable = row.getBooleanColumn("uapsd_enable"); - Long radioIdxTmp = getSingleValueFromSet(row, "vif_radio_idx"); - if (radioIdxTmp == null) { - radioIdxTmp = 0L; - } - wifiVifConfigInfo.vifRadioIdx = radioIdxTmp.intValue(); - wifiVifConfigInfo.security = row.getMapColumn("security"); - - if (row.getColumns().get("vlan_id") != null && row.getColumns().get("vlan_id").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - wifiVifConfigInfo.vlanId = row.getIntegerColumn("vlan_id").intValue(); - } - ret.put(wifiVifConfigInfo.ifName + '_' + wifiVifConfigInfo.ssid, wifiVifConfigInfo); - } - - LOG.debug("Retrieved WifiVifConfigs: {}", ret); - - } - catch (ExecutionException | InterruptedException | OvsdbClientException | TimeoutException e) { - LOG.error("Error in getProvisionedWifiVifConfigs", e); - throw new RuntimeException(e); - } - - return ret; - } - - public Map getProvisionedWifiInetConfigs(OvsdbClient ovsdbClient) { - Map ret = new HashMap<>(); - - List operations = new ArrayList<>(); - List conditions = new ArrayList<>(); - List columns = new ArrayList<>(); - columns.add("NAT"); - columns.add("_uuid"); - columns.add("broadcast"); - columns.add("enabled"); - columns.add("if_name"); - columns.add("if_type"); - columns.add("ip_assign_scheme"); - columns.add("network"); - columns.add("inet_addr"); - columns.add("mtu"); - columns.add("netmask"); - columns.add("vlan_id"); - - try { - LOG.debug("Retrieving WifiInetConfig:"); - - operations.add(new Select(wifiInetConfigDbTable, conditions, columns)); - CompletableFuture 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()) { - - WifiInetConfigInfo wifiInetConfigInfo = new WifiInetConfigInfo(); - Boolean natTmp = getSingleValueFromSet(row, "NAT"); - wifiInetConfigInfo.nat = natTmp != null ? natTmp : false; - - wifiInetConfigInfo.uuid = row.getUuidColumn("_uuid"); - if (row.getColumns().get("broadcast") != null && row.getColumns().get("broadcast").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - wifiInetConfigInfo.broadcast = row.getStringColumn("broadcast"); - } - wifiInetConfigInfo.enabled = row.getBooleanColumn("enabled"); - wifiInetConfigInfo.ifName = row.getStringColumn("if_name"); - wifiInetConfigInfo.ifType = row.getStringColumn("if_type"); - wifiInetConfigInfo.ipAssignScheme = row.getStringColumn("ip_assign_scheme"); - wifiInetConfigInfo.network = row.getBooleanColumn("network"); - if (row.getColumns().get("inet_addr") != null && row.getColumns().get("inet_addr").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - wifiInetConfigInfo.inetAddr = row.getStringColumn("inet_addr"); - } - if (row.getColumns().get("mtu") != null && row.getColumns().get("mtu").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - wifiInetConfigInfo.mtu = row.getIntegerColumn("mtu").intValue(); - } - if (row.getColumns().get("netmask") != null && row.getColumns().get("netmask").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - wifiInetConfigInfo.netmask = row.getStringColumn("netmask"); - } - if (row.getColumns().get("vlan_id") != null && row.getColumns().get("vlan_id").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - wifiInetConfigInfo.vlanId = row.getIntegerColumn("vlan_id").intValue(); - } - ret.put(wifiInetConfigInfo.ifName, wifiInetConfigInfo); - } - - LOG.debug("Retrieved WifiInetConfigs: {}", ret); - - } - catch (ExecutionException | InterruptedException | OvsdbClientException | TimeoutException e) { - LOG.error("Error in getProvisionedWifiInetConfigs", e); - throw new RuntimeException(e); - } - - return ret; - } - - public Map getProvisionedWifiStatsConfigs(OvsdbClient ovsdbClient) { - Map ret = new HashMap<>(); - - List operations = new ArrayList<>(); - List conditions = new ArrayList<>(); - List columns = new ArrayList<>(); - columns.add("channel_list"); - columns.add("radio_type"); - columns.add("reporting_interval"); - columns.add("sampling_interval"); - columns.add("stats_type"); - columns.add("survey_interval_ms"); - columns.add("survey_type"); - columns.add("threshold"); - columns.add("_uuid"); - - try { - LOG.debug("Retrieving WifiStatsConfigs:"); - - operations.add(new Select(wifiStatsConfigDbTable, conditions, columns)); - CompletableFuture 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()) { - - WifiStatsConfigInfo wifiStatsConfigInfo = new WifiStatsConfigInfo(); - - wifiStatsConfigInfo.channelList = row.getSetColumn("channel_list"); - wifiStatsConfigInfo.radioType = row.getStringColumn("radio_type"); - wifiStatsConfigInfo.reportingInterval = row.getIntegerColumn("reporting_interval").intValue(); - wifiStatsConfigInfo.samplingInterval = row.getIntegerColumn("sampling_interval").intValue(); - wifiStatsConfigInfo.statsType = row.getStringColumn("stats_type"); - wifiStatsConfigInfo.surveyType = getSingleValueFromSet(row, "survey_type"); - Long tmp = getSingleValueFromSet(row, "survey_interval_ms"); - wifiStatsConfigInfo.surveyIntervalMs = tmp != null ? tmp.intValue() : 0; - wifiStatsConfigInfo.threshold = row.getMapColumn("threshold"); - wifiStatsConfigInfo.uuid = row.getUuidColumn("_uuid"); - - if (wifiStatsConfigInfo.surveyType == null) { - ret.put(wifiStatsConfigInfo.radioType + "_" + wifiStatsConfigInfo.statsType, wifiStatsConfigInfo); - } - else { - ret.put(wifiStatsConfigInfo.radioType + "_" + wifiStatsConfigInfo.statsType + "_" - + wifiStatsConfigInfo.surveyType, wifiStatsConfigInfo); - - } - } - - LOG.debug("Retrieved WifiStatsConfigs: {}", ret); - - } - catch (ExecutionException | InterruptedException | OvsdbClientException | TimeoutException e) { - LOG.error("Error in getProvisionedWifiStatsConfigs", e); - - throw new RuntimeException(e); - } - - return ret; - } - - public void provisionSingleBridgePortInterface(OvsdbClient ovsdbClient, String interfaceName, String bridgeName, - String interfaceType, Map interfaceOptions, - Map provisionedInterfaces, Map provisionedPorts, - Map provisionedBridges) - throws OvsdbClientException, TimeoutException, ExecutionException, InterruptedException { - - LOG.debug("InterfaceName {} BridgeName {} InterfaceType {}", interfaceName, bridgeName, interfaceType); - if (!provisionedInterfaces.containsKey(interfaceName)) { - // Create this interface and link it to the port and the bridge - List operations = new ArrayList<>(); - Map updateColumns = new HashMap<>(); - List conditions = new ArrayList<>(); - - updateColumns.put("name", new Atom<>(interfaceName)); - if (interfaceType != null) { - updateColumns.put("type", new Atom<>(interfaceType)); - } - // updateColumns.put("admin_state", new Atom("up") ); - // updateColumns.put("link_state", new Atom("up") ); - // updateColumns.put("ifindex", new Atom(ifIndex) ); - // updateColumns.put("mtu", new Atom(1500) ); - // updateColumns.put("ofport", new Atom(ofport) ); - - if (interfaceOptions != null) { - @SuppressWarnings("unchecked") - com.vmware.ovsdb.protocol.operation.notation.Map ifOptions = com.vmware.ovsdb.protocol.operation.notation.Map - .of(interfaceOptions); - updateColumns.put("options", ifOptions); - } - - Uuid interfaceUuid = null; - - Row row = new Row(updateColumns); - operations.add(new Insert(interfaceDbTable, row)); - - { - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - - LOG.debug("Provisioned Interface for {}", interfaceName); - - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - if (res instanceof InsertResult) { - interfaceUuid = ((InsertResult) res).getUuid(); - } - } - } - - if (interfaceUuid == null) { - throw new IllegalStateException("Interface entry was not created successfully"); - } - - Uuid portUuid = null; - operations = new ArrayList<>(); - // link the interface to the port, create port if necessary - if (!provisionedPorts.containsKey(interfaceName)) { - // need to create port - updateColumns = new HashMap<>(); - - // portUuid = new Uuid(new UUID(System.currentTimeMillis(), - // System.nanoTime())) ; - updateColumns.put("name", new Atom<>(interfaceName)); - // updateColumns.put("_uuid", new Atom(portUuid)); - - Set portInterfacesSet = new HashSet<>(); - portInterfacesSet.add(interfaceUuid); - com.vmware.ovsdb.protocol.operation.notation.Set portInterfaces = com.vmware.ovsdb.protocol.operation.notation.Set - .of(portInterfacesSet); - updateColumns.put("interfaces", portInterfaces); - - row = new Row(updateColumns); - operations.add(new Insert(portDbTable, row)); - - { - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - - LOG.debug("Provisioned Port for {}", interfaceName); - - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - if (res instanceof InsertResult) { - portUuid = ((InsertResult) res).getUuid(); - } - } - } - - } - else { - // need to update port - PortInfo existingPort = provisionedPorts.get(interfaceName); - portUuid = existingPort.uuid; - - conditions = new ArrayList<>(); - updateColumns = new HashMap<>(); - - conditions.add(new Condition("name", Function.EQUALS, new Atom<>(interfaceName))); - - Set portInterfacesSet = new HashSet<>(); - if (existingPort.interfaceUuids != null) { - portInterfacesSet.addAll(existingPort.interfaceUuids); - } - portInterfacesSet.add(interfaceUuid); - com.vmware.ovsdb.protocol.operation.notation.Set portInterfaces = com.vmware.ovsdb.protocol.operation.notation.Set - .of(portInterfacesSet); - updateColumns.put("interfaces", portInterfaces); - - row = new Row(updateColumns); - operations.add(new Update(portDbTable, row)); - - { - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - - LOG.debug("Updated Port for {}", interfaceName); - - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - } - } - - } - - if (portUuid == null) { - throw new IllegalStateException("Port entry was not created successfully"); - } + public Map getProvisionedPorts(OvsdbClient ovsdbClient) { + Map ret = new HashMap<>(); - operations = new ArrayList<>(); + List operations = new ArrayList<>(); + List conditions = new ArrayList<>(); + List columns = new ArrayList<>(); + columns.add("name"); + columns.add("_uuid"); + columns.add("interfaces"); - // link the port to the bridge - if (provisionedBridges.containsKey(bridgeName)) { - BridgeInfo existingBridge = provisionedBridges.get(bridgeName); + try { + LOG.debug("Retrieving Ports:"); - conditions = new ArrayList<>(); - updateColumns = new HashMap<>(); - - conditions.add(new Condition("name", Function.EQUALS, new Atom<>(bridgeName))); + operations.add(new Select(portDbTable, conditions, columns)); + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - Set bridgePortsSet = new HashSet<>(); - if (existingBridge.portUuids != null) { - bridgePortsSet.addAll(existingBridge.portUuids); - } - - bridgePortsSet.add(portUuid); - com.vmware.ovsdb.protocol.operation.notation.Set bridgePorts = com.vmware.ovsdb.protocol.operation.notation.Set - .of(bridgePortsSet); - updateColumns.put("ports", bridgePorts); + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + } - row = new Row(updateColumns); - operations.add(new Update(bridgeDbTable, row)); + for (Row row : ((SelectResult) result[0]).getRows()) { - } - else { - LOG.warn("provisionedBridges does not have bridge {} - {} - port will be dangling", bridgeName, - provisionedBridges.keySet()); - } + PortInfo portInfo = new PortInfo(); + portInfo.name = row.getStringColumn("name"); + portInfo.uuid = row.getUuidColumn("_uuid"); + portInfo.interfaceUuids = row.getSetColumn("interfaces"); - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + 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 getProvisionedBridges(OvsdbClient ovsdbClient) { + Map ret = new HashMap<>(); + + List operations = new ArrayList<>(); + List conditions = new ArrayList<>(); + List 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 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 getProvisionedWifiRadioConfigs(OvsdbClient ovsdbClient) { + Map ret = new HashMap<>(); + + List operations = new ArrayList<>(); + List conditions = new ArrayList<>(); + List columns = new ArrayList<>(); + + columns.add("_uuid"); + columns.add("if_name"); + columns.add("bcn_int"); + columns.add("channel"); + columns.add("channel_mode"); + columns.add("country"); + columns.add("enabled"); + columns.add("ht_mode"); + columns.add("tx_power"); + columns.add("vif_configs"); + columns.add("freq_band"); + columns.add("hw_config"); + columns.add("hw_type"); + + try { + LOG.debug("Retrieving WifiRadioConfig:"); + + operations.add(new Select(wifiRadioConfigDbTable, conditions, columns)); + CompletableFuture 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()) { + + WifiRadioConfigInfo wifiRadioConfigInfo = new WifiRadioConfigInfo(); + wifiRadioConfigInfo.uuid = row.getUuidColumn("_uuid"); + wifiRadioConfigInfo.ifName = row.getStringColumn("if_name"); + Long beaconTmp = getSingleValueFromSet(row, "bcn_int"); + if (beaconTmp == null) { + beaconTmp = 0L; + } + wifiRadioConfigInfo.beaconInterval = beaconTmp.intValue(); + Long channelTmp = getSingleValueFromSet(row, "channel"); + if (channelTmp == null) { + channelTmp = -1L; + } + wifiRadioConfigInfo.channel = channelTmp.intValue(); + wifiRadioConfigInfo.channelMode = getSingleValueFromSet(row, "channel_mode"); + wifiRadioConfigInfo.country = getSingleValueFromSet(row, "country"); + Boolean tmp = getSingleValueFromSet(row, "enabled"); + wifiRadioConfigInfo.enabled = tmp != null ? tmp : false; + wifiRadioConfigInfo.htMode = getSingleValueFromSet(row, "ht_mode"); + wifiRadioConfigInfo.txPower = getSingleValueFromSet(row, "txPower"); + wifiRadioConfigInfo.vifConfigUuids = row.getSetColumn("vif_configs"); + wifiRadioConfigInfo.freqBand = row.getStringColumn("freq_band"); + wifiRadioConfigInfo.hwConfig = row.getMapColumn("hw_config"); + wifiRadioConfigInfo.hwType = row.getStringColumn("hw_type"); + ret.put(wifiRadioConfigInfo.ifName, wifiRadioConfigInfo); + } + + LOG.debug("Retrieved WifiRadioConfig: {}", ret); + + } catch (ExecutionException | InterruptedException | OvsdbClientException | TimeoutException e) { + LOG.error("Error in getProvisionedWifiRadioConfigs", e); + throw new RuntimeException(e); + } + + return ret; + } + + public Map getProvisionedWifiVifConfigs(OvsdbClient ovsdbClient) { + Map ret = new HashMap<>(); + + List operations = new ArrayList<>(); + List conditions = new ArrayList<>(); + List columns = new ArrayList<>(); + columns.add("bridge"); + columns.add("ap_bridge"); + columns.add("_uuid"); + columns.add("btm"); + columns.add("enabled"); + columns.add("ft_psk"); + columns.add("group_rekey"); + columns.add("if_name"); + columns.add("min_hw_mode"); + columns.add("mode"); + columns.add("rrm"); + columns.add("ssid"); + columns.add("ssid_broadcast"); + columns.add("uapsd_enable"); + columns.add("vif_radio_idx"); + columns.add("security"); + columns.add("vlan_id"); + + try { + LOG.debug("Retrieving WifiVifConfig:"); + + operations.add(new Select(wifiVifConfigDbTable, conditions, columns)); + CompletableFuture 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()) { + + WifiVifConfigInfo wifiVifConfigInfo = new WifiVifConfigInfo(); + wifiVifConfigInfo.bridge = row.getStringColumn("bridge"); + wifiVifConfigInfo.apBridge = row.getBooleanColumn("ap_bridge"); + wifiVifConfigInfo.uuid = row.getUuidColumn("_uuid"); + wifiVifConfigInfo.btm = row.getIntegerColumn("btm").intValue(); + wifiVifConfigInfo.enabled = row.getBooleanColumn("enabled"); + wifiVifConfigInfo.ftPsk = row.getIntegerColumn("ft_psk").intValue(); + wifiVifConfigInfo.groupRekey = row.getIntegerColumn("group_rekey").intValue(); + wifiVifConfigInfo.minHwMode = row.getStringColumn("min_hw_mode"); + wifiVifConfigInfo.ifName = row.getStringColumn("if_name"); + wifiVifConfigInfo.mode = row.getStringColumn("mode"); + wifiVifConfigInfo.rrm = row.getIntegerColumn("rrm").intValue(); + wifiVifConfigInfo.ssid = row.getStringColumn("ssid"); + wifiVifConfigInfo.ssidBroadcast = row.getStringColumn("ssid_broadcast"); + wifiVifConfigInfo.uapsdEnable = row.getBooleanColumn("uapsd_enable"); + Long radioIdxTmp = getSingleValueFromSet(row, "vif_radio_idx"); + if (radioIdxTmp == null) { + radioIdxTmp = 0L; + } + wifiVifConfigInfo.vifRadioIdx = radioIdxTmp.intValue(); + wifiVifConfigInfo.security = row.getMapColumn("security"); + + if (row.getColumns().get("vlan_id") != null && row.getColumns().get("vlan_id").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + wifiVifConfigInfo.vlanId = row.getIntegerColumn("vlan_id").intValue(); + } + ret.put(wifiVifConfigInfo.ifName + '_' + wifiVifConfigInfo.ssid, wifiVifConfigInfo); + } + + LOG.debug("Retrieved WifiVifConfigs: {}", ret); + + } catch (ExecutionException | InterruptedException | OvsdbClientException | TimeoutException e) { + LOG.error("Error in getProvisionedWifiVifConfigs", e); + throw new RuntimeException(e); + } + + return ret; + } + + public Map getProvisionedWifiInetConfigs(OvsdbClient ovsdbClient) { + Map ret = new HashMap<>(); + + List operations = new ArrayList<>(); + List conditions = new ArrayList<>(); + List columns = new ArrayList<>(); + columns.add("NAT"); + columns.add("_uuid"); + columns.add("broadcast"); + columns.add("enabled"); + columns.add("if_name"); + columns.add("if_type"); + columns.add("ip_assign_scheme"); + columns.add("network"); + columns.add("inet_addr"); + columns.add("mtu"); + columns.add("netmask"); + columns.add("vlan_id"); + + try { + LOG.debug("Retrieving WifiInetConfig:"); + + operations.add(new Select(wifiInetConfigDbTable, conditions, columns)); + CompletableFuture 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()) { + + WifiInetConfigInfo wifiInetConfigInfo = new WifiInetConfigInfo(); + Boolean natTmp = getSingleValueFromSet(row, "NAT"); + wifiInetConfigInfo.nat = natTmp != null ? natTmp : false; + + wifiInetConfigInfo.uuid = row.getUuidColumn("_uuid"); + if (row.getColumns().get("broadcast") != null && row.getColumns().get("broadcast").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + wifiInetConfigInfo.broadcast = row.getStringColumn("broadcast"); + } + wifiInetConfigInfo.enabled = row.getBooleanColumn("enabled"); + wifiInetConfigInfo.ifName = row.getStringColumn("if_name"); + wifiInetConfigInfo.ifType = row.getStringColumn("if_type"); + wifiInetConfigInfo.ipAssignScheme = row.getStringColumn("ip_assign_scheme"); + wifiInetConfigInfo.network = row.getBooleanColumn("network"); + if (row.getColumns().get("inet_addr") != null && row.getColumns().get("inet_addr").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + wifiInetConfigInfo.inetAddr = row.getStringColumn("inet_addr"); + } + if (row.getColumns().get("mtu") != null && row.getColumns().get("mtu").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + wifiInetConfigInfo.mtu = row.getIntegerColumn("mtu").intValue(); + } + if (row.getColumns().get("netmask") != null && row.getColumns().get("netmask").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + wifiInetConfigInfo.netmask = row.getStringColumn("netmask"); + } + if (row.getColumns().get("vlan_id") != null && row.getColumns().get("vlan_id").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + wifiInetConfigInfo.vlanId = row.getIntegerColumn("vlan_id").intValue(); + } + ret.put(wifiInetConfigInfo.ifName, wifiInetConfigInfo); + } + + LOG.debug("Retrieved WifiInetConfigs: {}", ret); + + } catch (ExecutionException | InterruptedException | OvsdbClientException | TimeoutException e) { + LOG.error("Error in getProvisionedWifiInetConfigs", e); + throw new RuntimeException(e); + } + + return ret; + } + + public Map getProvisionedWifiStatsConfigs(OvsdbClient ovsdbClient) { + Map ret = new HashMap<>(); + + List operations = new ArrayList<>(); + List conditions = new ArrayList<>(); + List columns = new ArrayList<>(); + columns.add("channel_list"); + columns.add("radio_type"); + columns.add("reporting_interval"); + columns.add("sampling_interval"); + columns.add("stats_type"); + columns.add("survey_interval_ms"); + columns.add("survey_type"); + columns.add("threshold"); + columns.add("_uuid"); + + try { + LOG.debug("Retrieving WifiStatsConfigs:"); + + operations.add(new Select(wifiStatsConfigDbTable, conditions, columns)); + CompletableFuture 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()) { + + WifiStatsConfigInfo wifiStatsConfigInfo = new WifiStatsConfigInfo(); + + wifiStatsConfigInfo.channelList = row.getSetColumn("channel_list"); + wifiStatsConfigInfo.radioType = row.getStringColumn("radio_type"); + wifiStatsConfigInfo.reportingInterval = row.getIntegerColumn("reporting_interval").intValue(); + wifiStatsConfigInfo.samplingInterval = row.getIntegerColumn("sampling_interval").intValue(); + wifiStatsConfigInfo.statsType = row.getStringColumn("stats_type"); + wifiStatsConfigInfo.surveyType = getSingleValueFromSet(row, "survey_type"); + Long tmp = getSingleValueFromSet(row, "survey_interval_ms"); + wifiStatsConfigInfo.surveyIntervalMs = tmp != null ? tmp.intValue() : 0; + wifiStatsConfigInfo.threshold = row.getMapColumn("threshold"); + wifiStatsConfigInfo.uuid = row.getUuidColumn("_uuid"); + + if (wifiStatsConfigInfo.surveyType == null) { + ret.put(wifiStatsConfigInfo.radioType + "_" + wifiStatsConfigInfo.statsType, wifiStatsConfigInfo); + } else { + ret.put(wifiStatsConfigInfo.radioType + "_" + wifiStatsConfigInfo.statsType + "_" + + wifiStatsConfigInfo.surveyType, wifiStatsConfigInfo); + + } + } + + LOG.debug("Retrieved WifiStatsConfigs: {}", ret); + + } catch (ExecutionException | InterruptedException | OvsdbClientException | TimeoutException e) { + LOG.error("Error in getProvisionedWifiStatsConfigs", e); + + throw new RuntimeException(e); + } + + return ret; + } + + public void provisionSingleBridgePortInterface(OvsdbClient ovsdbClient, String interfaceName, String bridgeName, + String interfaceType, Map interfaceOptions, + Map provisionedInterfaces, Map provisionedPorts, + Map provisionedBridges) + throws OvsdbClientException, TimeoutException, ExecutionException, InterruptedException { + + LOG.debug("InterfaceName {} BridgeName {} InterfaceType {}", interfaceName, bridgeName, interfaceType); + if (!provisionedInterfaces.containsKey(interfaceName)) { + // Create this interface and link it to the port and the bridge + List operations = new ArrayList<>(); + Map updateColumns = new HashMap<>(); + List conditions = new ArrayList<>(); + + updateColumns.put("name", new Atom<>(interfaceName)); + if (interfaceType != null) { + updateColumns.put("type", new Atom<>(interfaceType)); + } + // updateColumns.put("admin_state", new Atom("up") ); + // updateColumns.put("link_state", new Atom("up") ); + // updateColumns.put("ifindex", new Atom(ifIndex) ); + // updateColumns.put("mtu", new Atom(1500) ); + // updateColumns.put("ofport", new Atom(ofport) ); + + if (interfaceOptions != null) { + @SuppressWarnings("unchecked") + com.vmware.ovsdb.protocol.operation.notation.Map ifOptions = com.vmware.ovsdb.protocol.operation.notation.Map + .of(interfaceOptions); + updateColumns.put("options", ifOptions); + } + + Uuid interfaceUuid = null; + + Row row = new Row(updateColumns); + operations.add(new Insert(interfaceDbTable, row)); + + { + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + + LOG.debug("Provisioned Interface for {}", interfaceName); + + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + if (res instanceof InsertResult) { + interfaceUuid = ((InsertResult) res).getUuid(); + } + } + } + + if (interfaceUuid == null) { + throw new IllegalStateException("Interface entry was not created successfully"); + } + + Uuid portUuid = null; + operations = new ArrayList<>(); + // link the interface to the port, create port if necessary + if (!provisionedPorts.containsKey(interfaceName)) { + // need to create port + updateColumns = new HashMap<>(); + + // portUuid = new Uuid(new UUID(System.currentTimeMillis(), + // System.nanoTime())) ; + updateColumns.put("name", new Atom<>(interfaceName)); + // updateColumns.put("_uuid", new Atom(portUuid)); + + Set portInterfacesSet = new HashSet<>(); + portInterfacesSet.add(interfaceUuid); + com.vmware.ovsdb.protocol.operation.notation.Set portInterfaces = com.vmware.ovsdb.protocol.operation.notation.Set + .of(portInterfacesSet); + updateColumns.put("interfaces", portInterfaces); + + row = new Row(updateColumns); + operations.add(new Insert(portDbTable, row)); + + { + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + + LOG.debug("Provisioned Port for {}", interfaceName); + + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + if (res instanceof InsertResult) { + portUuid = ((InsertResult) res).getUuid(); + } + } + } + + } else { + // need to update port + PortInfo existingPort = provisionedPorts.get(interfaceName); + portUuid = existingPort.uuid; + + conditions = new ArrayList<>(); + updateColumns = new HashMap<>(); + + conditions.add(new Condition("name", Function.EQUALS, new Atom<>(interfaceName))); + + Set portInterfacesSet = new HashSet<>(); + if (existingPort.interfaceUuids != null) { + portInterfacesSet.addAll(existingPort.interfaceUuids); + } + portInterfacesSet.add(interfaceUuid); + com.vmware.ovsdb.protocol.operation.notation.Set portInterfaces = com.vmware.ovsdb.protocol.operation.notation.Set + .of(portInterfacesSet); + updateColumns.put("interfaces", portInterfaces); + + row = new Row(updateColumns); + operations.add(new Update(portDbTable, row)); + + { + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + + LOG.debug("Updated Port for {}", interfaceName); + + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + } + } + + } - if (LOG.isDebugEnabled()) { - LOG.debug("Finished provisioning Interface/port/bridge for {} / {}", interfaceName, bridgeName); + if (portUuid == null) { + throw new IllegalStateException("Port entry was not created successfully"); + } - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - } - } + operations = new ArrayList<>(); - } - } + // link the port to the bridge + if (provisionedBridges.containsKey(bridgeName)) { + BridgeInfo existingBridge = provisionedBridges.get(bridgeName); - // public static final String homeAp24 = "home-ap-24"; - // public static final String homeApL50 = "home-ap-l50"; - // public static final String homeApU50 = "home-ap-u50"; + conditions = new ArrayList<>(); + updateColumns = new HashMap<>(); - public static final String brWan = "br-wan"; - public static final String brLan = "br-lan"; + conditions.add(new Condition("name", Function.EQUALS, new Atom<>(bridgeName))); - public static final String patchW2h = "patch-w2h"; - public static final String patchH2w = "patch-h2w"; + Set bridgePortsSet = new HashSet<>(); + if (existingBridge.portUuids != null) { + bridgePortsSet.addAll(existingBridge.portUuids); + } - public void provisionBridgePortInterface(OvsdbClient ovsdbClient) { - try { - Map provisionedInterfaces = getProvisionedInterfaces(ovsdbClient); - LOG.debug("Existing Interfaces: {}", provisionedInterfaces.keySet()); + bridgePortsSet.add(portUuid); + com.vmware.ovsdb.protocol.operation.notation.Set bridgePorts = com.vmware.ovsdb.protocol.operation.notation.Set + .of(bridgePortsSet); + updateColumns.put("ports", bridgePorts); - Map provisionedPorts = getProvisionedPorts(ovsdbClient); - LOG.debug("Existing Ports: {}", provisionedPorts.keySet()); + row = new Row(updateColumns); + operations.add(new Update(bridgeDbTable, row)); - Map provisionedBridges = getProvisionedBridges(ovsdbClient); - LOG.debug("Existing Bridges: {}", provisionedBridges.keySet()); + } else { + LOG.warn("provisionedBridges does not have bridge {} - {} - port will be dangling", bridgeName, + provisionedBridges.keySet()); + } - Map patchH2wOptions = new HashMap<>(); - patchH2wOptions.put("peer", "patch-w2h"); + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - Map patchW2hOptions = new HashMap<>(); - patchH2wOptions.put("peer", "patch-h2w"); + if (LOG.isDebugEnabled()) { + LOG.debug("Finished provisioning Interface/port/bridge for {} / {}", interfaceName, bridgeName); - provisionSingleBridgePortInterface(ovsdbClient, patchH2w, bridgeNameVifInterfaces, "patch", patchH2wOptions, - provisionedInterfaces, provisionedPorts, provisionedBridges); - provisionSingleBridgePortInterface(ovsdbClient, patchW2h, brWan, "patch", patchW2hOptions, - provisionedInterfaces, provisionedPorts, provisionedBridges); + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + } + } - provisionSingleBridgePortInterface(ovsdbClient, ifName5GHzU, bridgeNameVifInterfaces, "vif", null, - provisionedInterfaces, provisionedPorts, provisionedBridges); - provisionSingleBridgePortInterface(ovsdbClient, ifName5GHzL, bridgeNameVifInterfaces, "vif", null, - provisionedInterfaces, provisionedPorts, provisionedBridges); - provisionSingleBridgePortInterface(ovsdbClient, ifName2pt4GHz, bridgeNameVifInterfaces, "vif", null, - provisionedInterfaces, provisionedPorts, provisionedBridges); + } + } - } - catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { - LOG.error("Error in provisionBridgePortInterface", e); - throw new RuntimeException(e); - } + // public static final String homeAp24 = "home-ap-24"; + // public static final String homeApL50 = "home-ap-l50"; + // public static final String homeApU50 = "home-ap-u50"; - } + public static final String brWan = "br-wan"; + public static final String brLan = "br-lan"; - public void removeOnboardingSsids(OvsdbClient ovsdbClient) { - try { - List operations = new ArrayList<>(); - List conditions = new ArrayList<>(); - conditions.add(new Condition("ssid", Function.EQUALS, new Atom<>("opensync.onboard"))); + public static final String patchW2h = "patch-w2h"; + public static final String patchH2w = "patch-h2w"; - operations.add(new Delete(wifiVifConfigDbTable, conditions)); + public void provisionBridgePortInterface(OvsdbClient ovsdbClient) { + try { + Map provisionedInterfaces = getProvisionedInterfaces(ovsdbClient); + LOG.debug("Existing Interfaces: {}", provisionedInterfaces.keySet()); - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - - if (LOG.isDebugEnabled()) { - LOG.debug("Removed onboarding SSIDs from {}:", wifiVifConfigDbTable); - - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - } - } - - } - catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { - LOG.error("Error in removeOnboardingSsids", e); - throw new RuntimeException(e); - } - - } - - public void removeAllSsids(OvsdbClient ovsdbClient) { - try { - List operations = new ArrayList<>(); - - operations.add(new Delete(wifiVifConfigDbTable)); - - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - - if (LOG.isDebugEnabled()) { - LOG.debug("Removed all existing SSIDs from {}:", wifiVifConfigDbTable); - - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - } - } - - // Now clean up references in the vif_configs columns - operations = new ArrayList<>(); - Map updateColumns = new HashMap<>(); - Set vifConfigsSet = new HashSet<>(); - com.vmware.ovsdb.protocol.operation.notation.Set vifConfigs = com.vmware.ovsdb.protocol.operation.notation.Set - .of(vifConfigsSet); - updateColumns.put("vif_configs", vifConfigs); - - Row row = new Row(updateColumns); - operations.add(new Update(wifiRadioConfigDbTable, row)); - - fResult = ovsdbClient.transact(ovsdbName, operations); - result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - - if (LOG.isDebugEnabled()) { - LOG.debug("Updated WifiRadioConfig "); - - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - } - } - - LOG.info("Removed all ssids"); - - } - catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { - LOG.error("Error in removeAllSsids", e); - throw new RuntimeException(e); - } - - } - - public void configureWifiRadios(OvsdbClient ovsdbClient, OpensyncAPConfig opensyncAPConfig) { - - Map provisionedWifiRadios = getProvisionedWifiRadioConfigs(ovsdbClient); - LOG.debug("Existing WifiRadioConfigs: {}", provisionedWifiRadios.keySet()); - - String country = opensyncAPConfig.getCountryCode(); // should be the - // same for all - // radios on this AP - // ;-) - - ApElementConfiguration apElementConfiguration = (ApElementConfiguration) opensyncAPConfig.getCustomerEquipment() - .getDetails(); - - for (RadioType radioType : apElementConfiguration.getRadioMap().keySet()) { - Map hwConfig = new HashMap<>(); - - ElementRadioConfiguration elementRadioConfig = apElementConfiguration.getRadioMap().get(radioType); - int channel = elementRadioConfig.getChannelNumber(); - ChannelBandwidth bandwidth = elementRadioConfig.getChannelBandwidth(); - String ht_mode = null; - switch (bandwidth) { - case is20MHz: - ht_mode = "HT20"; - break; - case is40MHz: - ht_mode = "HT40"; - break; - case is80MHz: - ht_mode = "HT80"; - break; - case is160MHz: - ht_mode = "HT160"; - break; - default: - ht_mode = "HT20"; - } - elementRadioConfig.getAutoChannelSelection(); - - RadioConfiguration radioConfig = apElementConfiguration.getAdvancedRadioMap().get(radioType); - int beaconInterval = radioConfig.getBeaconInterval(); - boolean enabled = radioConfig.getRadioAdminState().equals(StateSetting.enabled); - - int txPower = 0; - if (!elementRadioConfig.getEirpTxPower().isAuto()) { - txPower = elementRadioConfig.getEirpTxPower().getValue(); - } - String configName = null; - switch (radioType) { - case is2dot4GHz: - configName = radioName2pt4GHz; - break; - case is5GHz: - // 802.11h dfs (Dynamic Frequency Selection) aka military and - // weather radar - // avoidance protocol - // Must not be disabled (by law) - // NA for 2.4GHz - hwConfig.put("dfs_enable", "1"); - hwConfig.put("dfs_ignorecac", "0"); - hwConfig.put("dfs_usenol", "1"); - configName = radioName5GHzU; - break; - case is5GHzL: - // 802.11h dfs (Dynamic Frequency Selection) aka military and - // weather radar - // avoidance protocol - // Must not be disabled (by law) - // NA for 2.4GHz - hwConfig.put("dfs_enable", "1"); - hwConfig.put("dfs_ignorecac", "0"); - hwConfig.put("dfs_usenol", "1"); - configName = radioName5GHzL; - break; - case is5GHzU: - // 802.11h dfs (Dynamic Frequency Selection) aka military and - // weather radar - // avoidance protocol - // Must not be disabled (by law) - // NA for 2.4GHz - hwConfig.put("dfs_enable", "1"); - hwConfig.put("dfs_ignorecac", "0"); - hwConfig.put("dfs_usenol", "1"); - configName = radioName5GHzU; - break; - default: // don't know this interface - continue; - - } - - if (configName != null) { - try { - configureWifiRadios(ovsdbClient, configName, provisionedWifiRadios, channel, hwConfig, country, - beaconInterval, enabled, ht_mode, txPower); - } - catch (OvsdbClientException e) { - LOG.error("ConfigureWifiRadios failed with OvsdbClient exception.", e); - } - catch (TimeoutException e) { - LOG.error("ConfigureWifiRadios failed with Timeout.", e); - - } - catch (ExecutionException e) { - LOG.error("ConfigureWifiRadios excecution failed.", e); - - } - catch (InterruptedException e) { - LOG.error("ConfigureWifiRadios interrupted.", e); - } - - } - - } - - } - - public List getOpensyncAPRadioState(TableUpdates tableUpdates, String apId, - OvsdbClient ovsdbClient) { - - List ret = new ArrayList<>(); - - try { - - for (Entry tableUpdate : tableUpdates.getTableUpdates().entrySet()) { - - for (Entry rowUpdate : tableUpdate.getValue().getRowUpdates().entrySet()) { - - Row row = rowUpdate.getValue().getNew(); - // Row old = rowUpdate.getOld(); - - if (row != null) { - - OpensyncAPRadioState tableState = new OpensyncAPRadioState(); - - 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 (map.get("channel") != null && map.get("channel").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setChannel(row.getIntegerColumn("channel").intValue()); - } - if (map.get("freq_band") != null && map.get("freq_band").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - String frequencyBand = row.getStringColumn("freq_band"); - switch (frequencyBand) { - case "2.4G": - tableState.setFreqBand(RadioType.is2dot4GHz); - break; - case "5G": - tableState.setFreqBand(RadioType.is5GHz); - break; - case "5GL": - tableState.setFreqBand(RadioType.is5GHzL); - break; - case "5GU": - tableState.setFreqBand(RadioType.is5GHzU); - break; - default: - tableState.setFreqBand(RadioType.UNSUPPORTED); - } - } - if (map.get("if_name") != null && map.get("if_name").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setIfName(row.getStringColumn("if_name")); - } - if (map.get("channel_mode") != null && map.get("channel_mode").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setChannelMode(row.getStringColumn("channel_mode")); - } - if (map.get("country") != null && map.get("country").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setCountry(row.getStringColumn("country")); - } - if (map.get("enabled") != null && map.get("enabled").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setEnabled(row.getBooleanColumn("enabled")); - } - if (map.get("ht_mode") != null && map.get("ht_mode").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setHtMode(row.getStringColumn("ht_mode")); - } - if (map.get("tx_power") != null && map.get("tx_power").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setTxPower(row.getIntegerColumn("tx_power").intValue()); - } - if (map.get("hw_config") != null && map.get("hw_config").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Map.class)) { - tableState.setHwConfig(row.getMapColumn("hw_config")); - } - 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")); - } - if (map.get("allowed_channels") != null) { - - Set allowedChannels = getSet(row, "allowed_channels"); - - Set allowed = new HashSet<>(); - for (Long channel : allowedChannels) { - allowed.add(channel.intValue()); - } - tableState.setAllowedChannels(allowed); - } - - ret.add(tableState); - } - } - } - - ret.stream().forEach(wrs -> { - LOG.debug("Wifi_Radio_State row {}", wrs); - }); - - } - catch (Exception e) { - LOG.error("Could not parse update for Wifi_Radio_State", e); - } - - return ret; - } - - public List getOpensyncAPInetState(TableUpdates tableUpdates, String apId, - OvsdbClient ovsdbClient) { - List ret = new ArrayList<>(); - - try { - - for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) { - - for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) { - - Row row = rowUpdate.getNew(); - // Row old = rowUpdate.getOld(); - - if (row != null) { - - OpensyncAPInetState tableState = new OpensyncAPInetState(); - Map map = row.getColumns(); - - if (map.get("NAT") != null && map.get("NAT").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setNat(row.getBooleanColumn("NAT")); - } - if (map.get("enabled") != null && map.get("enabled").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setEnabled(row.getBooleanColumn("enabled")); - } - if (map.get("if_name") != null && map.get("if_name").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setIfName(row.getStringColumn("if_name")); - } - if (map.get("if_type") != null && map.get("if_type").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setIfType(row.getStringColumn("if_type")); - } - if (map.get("ip_assign_scheme") != null && map.get("ip_assign_scheme").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setIpAssignScheme(row.getStringColumn("ip_assign_scheme")); - } - if (map.get("network") != null && map.get("network").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setNetwork(row.getBooleanColumn("network")); - } - if (map.get("hwaddr") != null && map.get("hwaddr").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setHwAddr(row.getStringColumn("hwaddr")); - } - 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")); - } - ret.add(tableState); - } - - } - } - - ret.stream().forEach(wrs -> { - LOG.debug("Wifi_Inet_State row {}", wrs); - }); - - } - catch (Exception e) { - LOG.error("Could not parse update for Wifi_Inet_State", e); - } - return ret; - } - - public List getOpensyncAPVIFState(TableUpdates tableUpdates, String apId, - OvsdbClient ovsdbClient) { - List ret = new ArrayList<>(); - try { - - for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) { - - for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) { - - Row row = rowUpdate.getNew(); - // Row old = rowUpdate.getOld(); - - if (row != null) { - - OpensyncAPVIFState tableState = new OpensyncAPVIFState(); - - 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 (map.get("bridge") != null && map.get("bridge").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setBridge(row.getStringColumn("bridge")); - } - if (map.get("btm") != null && map.get("btm").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setBtm(row.getIntegerColumn("btm").intValue()); - } - - if (map.get("channel") != null && map.get("channel").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setChannel(row.getIntegerColumn("channel").intValue()); - } - - if (map.get("enabled") != null && map.get("enabled").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setEnabled(row.getBooleanColumn("enabled")); - } - - if (map.get("group_rekey") != null && map.get("group_rekey").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setGroupRekey(row.getIntegerColumn("group_rekey").intValue()); - } - if (map.get("if_name") != null && map.get("if_name").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setIfName(row.getStringColumn("if_name")); - } - - if (map.get("mode") != null && map.get("mode").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setMode(row.getStringColumn("mode")); - } - - if (map.get("rrm") != null && map.get("rrm").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setRrm(row.getIntegerColumn("rrm").intValue()); - } - if (map.get("ssid") != null && map.get("ssid").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setSsid(row.getStringColumn("ssid")); - } - - if (map.get("ssid_broadcast") != null && map.get("ssid_broadcast").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setSsidBroadcast(row.getStringColumn("ssid_broadcast")); - } - if (map.get("uapsd_enable") != null && map.get("uapsd_enable").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setUapsdEnable(row.getBooleanColumn("uapsd_enable")); - } - if (map.get("vif_radio_idx") != null && map.get("vif_radio_idx").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setVifRadioIdx(row.getIntegerColumn("vif_radio_idx").intValue()); - } - - if (map.get("associated_clients") != null) { - tableState.setAssociatedClients(row.getSetColumn("associated_clients")); - } - - if (map.get("security") != null) { - tableState.setSecurity(row.getMapColumn("security")); - } - - 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")); - } - - ret.add(tableState); - - } - - } - } - - ret.stream().forEach(wrs -> { - LOG.debug("Wifi_VIF_State row {}", wrs); - }); - - } - catch (Exception e) { - LOG.error("Could not parse update for Wifi_VIF_State", e); - - } - return ret; - } - - public List getOpensyncWifiAssociatedClients(TableUpdates tableUpdates, String apId, - OvsdbClient ovsdbClient) { - List ret = new ArrayList<>(); - - try { - - for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) { - - for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) { - - Row row = rowUpdate.getNew(); - - if (row != null) { - - 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")); - } - - ret.add(tableState); - - } - } - } - ret.stream().forEach(wrs -> { - LOG.debug("Wifi_Associated_Clients row {}", wrs); - }); - } - catch (Exception e) { - LOG.error("Could not get Wifi_Associated_Clients list from table update", e); - } - - return ret; - } - - public OpensyncAWLANNode getOpensyncAWLANNode(TableUpdates tableUpdates, String apId, OvsdbClient ovsdbClient) { - OpensyncAWLANNode tableState = new OpensyncAWLANNode(); - - try { - - for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) { - - for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) { - - Row row = rowUpdate.getNew(); - - if (row != null) { - - Map map = row.getColumns(); - - if (map.get("mqtt_settings") != null) { - tableState.setMqttSettings(row.getMapColumn("mqtt_settings")); - } - if (map.get("mqtt_headers") != null) { - tableState.setMqttHeaders(row.getMapColumn("mqtt_headers")); - } - if (map.get("mqtt_topics") != null) { - tableState.setMqttHeaders(row.getMapColumn("mqtt_topics")); - } - - if (map.get("model") != null && map.get("model").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setModel(row.getStringColumn("model")); - } - if (map.get("sku_number") != null && map.get("sku_number").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setSkuNumber(row.getStringColumn("sku_number")); - } - if (map.get("id") != null && map.get("id").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setId(row.getStringColumn("id")); - } - - if (map.get("version_matrix") != null) { - tableState.setVersionMatrix(row.getMapColumn("version_matrix")); - } - if (map.get("firmware_version") != null && map.get("firmware_version").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setFirmwareVersion(row.getStringColumn("firmware_version")); - } - if (map.get("firmware_url") != null && map.get("firmware_url").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setFirmwareUrl(row.getStringColumn("firmware_url")); - } - - if (map.get("_uuid") != null && map.get("_uuid").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setVersion(row.getUuidColumn("_uuid")); - } - if (map.get("upgrade_dl_timer") != null && map.get("upgrade_dl_timer").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setUpgradeDlTimer(row.getIntegerColumn("upgrade_dl_timer").intValue()); - } - if (map.get("platform_version") != null && map.get("platform_version").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setPlatformVersion(row.getStringColumn("platform_version")); - } - if (map.get("firmware_pass") != null && map.get("firmware_pass").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setFirmwarePass(row.getStringColumn("firmware_pass")); - } - if (map.get("upgrade_timer") != null && map.get("upgrade_timer").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setUpgradeTimer(row.getIntegerColumn("upgrade_timer").intValue()); - } - if (map.get("max_backoff") != null && map.get("max_backoff").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setMaxBackoff(row.getIntegerColumn("max_backoff").intValue()); - } - if (map.get("led_config") != null) { - tableState.setLedConfig(row.getMapColumn("led_config")); - } - if (map.get("redirector_addr") != null && map.get("redirector_addr").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setRedirectorAddr(row.getStringColumn("redirector_addr")); - } - if (map.get("serial_number") != null && map.get("serial_number").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setSerialNumber(row.getStringColumn("serial_number")); - } - 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("upgrade_status") != null && map.get("upgrade_status").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setUpgradeTimer(row.getIntegerColumn("upgrade_status").intValue()); - } - if (map.get("device_mode") != null && map.get("device_mode").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setDeviceMode(row.getStringColumn("device_mode")); - } - if (map.get("min_backoff") != null && map.get("min_backoff").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setMinBackoff(row.getIntegerColumn("min_backoff").intValue()); - } - - if (map.get("revision") != null && map.get("revision").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setRevision(row.getStringColumn("revision")); - } - if (map.get("manager_addr") != null && map.get("manager_addr").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setManagerAddr(row.getStringColumn("manager_addr")); - } - if (map.get("factory_reset") != null && map.get("factory_reset").getClass() - .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { - tableState.setFactoryReset(row.getBooleanColumn("factory_reset")); - } - } - - } - - } - } - catch (Exception e) { - LOG.error("Failed to handle AWLAN_Node update", e); - } - - return tableState; - - } - - public void configureWifiRadios(OvsdbClient ovsdbClient, String configName, - Map provisionedWifiRadios, int channel, Map hwConfig, - String country, int beaconInterval, boolean enabled, String ht_mode, int txPower) - throws OvsdbClientException, TimeoutException, ExecutionException, InterruptedException { - - WifiRadioConfigInfo existingConfig = provisionedWifiRadios.get(configName); - - if (existingConfig == null) { - LOG.warn("There is no WifiRadioConfig {}", configName); - return; - } - - List operations = new ArrayList<>(); - Map updateColumns = new HashMap<>(); - List conditions = new ArrayList<>(); - conditions.add(new Condition("if_name", Function.EQUALS, new Atom<>(configName))); - - updateColumns.put("channel", new Atom<>(channel)); - updateColumns.put("country", new Atom<>(country)); - @SuppressWarnings("unchecked") - com.vmware.ovsdb.protocol.operation.notation.Map hwConfigMap = com.vmware.ovsdb.protocol.operation.notation.Map - .of(hwConfig); - updateColumns.put("hw_config", hwConfigMap); - updateColumns.put("bcn_int", new Atom<>(beaconInterval)); - updateColumns.put("enabled", new Atom<>(enabled)); - updateColumns.put("ht_mode", new Atom<>(ht_mode)); - if (txPower > 0) { - updateColumns.put("tx_power", new Atom<>(txPower)); - } - else { - updateColumns.put("tx_power", new com.vmware.ovsdb.protocol.operation.notation.Set()); - } - - Row row = new Row(updateColumns); - operations.add(new Update(wifiRadioConfigDbTable, conditions, row)); - - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - - LOG.debug("Provisioned channel {} for {}", channel, configName); - - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - } - } - - public void configureSingleSsid(OvsdbClient ovsdbClient, String bridge, String ifName, String ssid, - boolean ssidBroadcast, Map security, - Map provisionedWifiRadioConfigs, String radioIfName, int vlanId, - boolean rrmEnabled, String minHwMode, boolean enabled, int keyRefresh, boolean uapsdEnabled, - boolean apBridge, NetworkForwardMode networkForwardMode, String gateway, String inet, - Map dns, String ipAssignScheme) { - - List operations = new ArrayList<>(); - Map updateColumns = new HashMap<>(); - - try { - updateColumns.put("bridge", new Atom<>(bridge)); - updateColumns.put("btm", new Atom<>(1)); - updateColumns.put("enabled", new Atom<>(enabled)); - updateColumns.put("ft_psk", new Atom<>(0)); - updateColumns.put("if_name", new Atom<>(ifName)); - updateColumns.put("mode", new Atom<>("ap")); - updateColumns.put("rrm", new Atom<>(rrmEnabled ? 1 : 0)); - updateColumns.put("ssid", new Atom<>(ssid)); - updateColumns.put("ssid_broadcast", new Atom<>(ssidBroadcast ? "enabled" : "disabled")); - updateColumns.put("uapsd_enable", new Atom<>(true)); - // updateColumns.put("vif_radio_idx", new - // Atom(vifRadioIdx)); - updateColumns.put("min_hw_mode", new Atom<>(minHwMode)); - updateColumns.put("vlan_id", new Atom<>(vlanId)); - 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 securityMap = com.vmware.ovsdb.protocol.operation.notation.Map - .of(security); - updateColumns.put("security", securityMap); - - Row row = new Row(updateColumns); - operations.add(new Insert(wifiVifConfigDbTable, row)); - - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - - LOG.debug("Provisioned SSID {} on {}", ssid, ifName); - - Uuid vifConfigUuid = null; - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - if (res instanceof InsertResult) { - vifConfigUuid = ((InsertResult) res).getUuid(); - } - } - - if (vifConfigUuid == null) { - throw new IllegalStateException("Wifi_VIF_Config entry was not created successfully"); - } - - // update Wifi_Radio_Config here - add vifConfigUuid - /// usr/plume/tools/ovsh u Wifi_Radio_Config - // vif_configs:='["set",[["uuid","98e42897-b567-4186-84a6-4a4e38a51e9d"],["uuid","4314920e-c4e6-42a6-93e3-261142ed9adf"]]]' - // --where if_name==wifi0 - updateColumns.clear(); - operations.clear(); - - WifiRadioConfigInfo wifiRadioConfigInfo = provisionedWifiRadioConfigs.get(radioIfName); - if (wifiRadioConfigInfo == null) { - throw new IllegalStateException("missing Wifi_Radio_Config entry " + radioIfName); - } - - Set vifConfigsSet = new HashSet<>(wifiRadioConfigInfo.vifConfigUuids); - vifConfigsSet.add(vifConfigUuid); - com.vmware.ovsdb.protocol.operation.notation.Set vifConfigs = com.vmware.ovsdb.protocol.operation.notation.Set - .of(vifConfigsSet); - updateColumns.put("vif_configs", vifConfigs); - - List conditions = new ArrayList<>(); - conditions.add(new Condition("if_name", Function.EQUALS, new Atom<>(radioIfName))); - - row = new Row(updateColumns); - operations.add(new Update(wifiRadioConfigDbTable, conditions, row)); - - fResult = ovsdbClient.transact(ovsdbName, operations); - result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - - if (LOG.isDebugEnabled()) { - LOG.debug("Updated WifiRadioConfig {} for SSID {}:", radioIfName, ssid); - - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - } - } - Map inetConfigs = getProvisionedWifiInetConfigs(ovsdbClient); - if (inetConfigs.containsKey(ifName)) { - updateWifiInetConfig(ovsdbClient, vlanId, ifName, enabled, networkForwardMode == NetworkForwardMode.NAT, - "vif", gateway, inet, dns, ipAssignScheme, vifConfigUuid); - } - else { - LOG.debug("No corresponding WifiInetConfig for this Interface"); - insertWifiInetConfigForVif(ovsdbClient, vlanId, ifName, enabled, - networkForwardMode == NetworkForwardMode.NAT, "vif", gateway, inet, dns, ipAssignScheme, - vifConfigUuid); - } - - LOG.info("Provisioned SSID {} on interface {} / {}", ssid, ifName, radioIfName); - - } - catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { - LOG.error("Error in configureSingleSsid", e); - throw new RuntimeException(e); - } - } - - public void configureSsids(OvsdbClient ovsdbClient, OpensyncAPConfig opensyncApConfig) { - - boolean rrmEnabled = false; - if (opensyncApConfig.getEquipmentLocation() != null - && opensyncApConfig.getEquipmentLocation().getDetails() != null) { - rrmEnabled = opensyncApConfig.getEquipmentLocation().getDetails().isRrmEnabled(); - } - - for (Profile ssidProfile : opensyncApConfig.getSsidProfile()) { - - Map provisionedWifiVifConfigs = getProvisionedWifiVifConfigs(ovsdbClient); - LOG.debug("Existing WifiVifConfigs: {}", provisionedWifiVifConfigs.keySet()); - - SsidConfiguration ssidConfig = (SsidConfiguration) ssidProfile.getDetails(); - ApElementConfiguration apElementConfig = (ApElementConfiguration) opensyncApConfig.getCustomerEquipment() - .getDetails(); - for (RadioType radioType : ssidConfig.getAppliedRadios()) { - - int keyRefresh = ssidConfig.getKeyRefresh(); - - Map provisionedWifiRadioConfigs = getProvisionedWifiRadioConfigs( - ovsdbClient); - - boolean ssidBroadcast = ssidConfig.getBroadcastSsid() == StateSetting.enabled; - Map security = new HashMap<>(); - String ssidSecurityMode = ssidConfig.getSecureMode().name(); - String opensyncSecurityMode = "OPEN"; - - String ipAssignScheme = "none"; - // the following 5 attributes only applicable to static config, - // else they are - // ignored - String gateway = null; - String inet = null; - Map dns = null; - 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 if (apElementConfig.getGettingIP().equals(GettingIP.dhcp) - || apElementConfig.getGettingDNS().equals(GettingDNS.dhcp)) { - ipAssignScheme = "dhcp"; - } - - RadioConfiguration radioConfiguration = apElementConfig.getAdvancedRadioMap().get(radioType); - if (radioConfiguration == null) { - continue; // don't have a radio of this kind in the map - } - RadioMode radioMode = radioConfiguration.getRadioMode(); - - boolean uapsdEnabled = radioConfiguration.getUapsdState() == StateSetting.enabled; - - boolean apBridge = radioConfiguration.getStationIsolation() == StateSetting.enabled; // stationIsolation - - String minHwMode = "11n"; // min_hw_mode is 11ac, wifi 5, we can - // also take ++ (11ax) but 2.4GHz only - // Wifi4 -- - if (!radioType.equals(RadioType.is2dot4GHz)) { - minHwMode = "11ac"; - } - if (!radioType.equals(RadioType.is2dot4GHz) && radioMode.equals(RadioMode.modeX)) { - minHwMode = "11x"; - } - - if (ssidSecurityMode.equalsIgnoreCase("wpaPSK") || ssidSecurityMode.equalsIgnoreCase("wpa2PSK")) { - opensyncSecurityMode = "WPA-PSK"; - } - else if (ssidSecurityMode.equalsIgnoreCase("wep")) { - opensyncSecurityMode = "WEP"; - } - - security.put("encryption", opensyncSecurityMode); - // key and mode is N/A for OPEN security - if (!opensyncSecurityMode.equals("OPEN")) { - security.put("key", ssidConfig.getKeyStr()); - security.put("mode", Long.toString(ssidConfig.getSecureMode().getId())); - } - - boolean enabled = ssidConfig.getSsidAdminState().equals(StateSetting.enabled); - - String ifName = null; - String radioIfName = null; - - if (radioType == RadioType.is2dot4GHz) { - ifName = ifName2pt4GHz; - radioIfName = radioName2pt4GHz; - } - else if (radioType == RadioType.is5GHzL) { - ifName = ifName5GHzL; - radioIfName = radioName5GHzL; - } - else if (radioType == RadioType.is5GHzU) { - ifName = ifName5GHzU; - radioIfName = radioName5GHzU; - } - - if (!provisionedWifiVifConfigs.containsKey(ifName + "_" + ssidConfig.getSsid())) { - try { - configureSingleSsid(ovsdbClient, bridgeNameVifInterfaces, ifName, ssidConfig.getSsid(), - ssidBroadcast, security, provisionedWifiRadioConfigs, radioIfName, - ssidConfig.getVlanId(), rrmEnabled, minHwMode, enabled, keyRefresh, uapsdEnabled, - apBridge, ssidConfig.getForwardMode(), gateway, inet, dns, ipAssignScheme); - - } - catch (IllegalStateException e) { - // could not provision this SSID, but still can go on - LOG.warn("could not provision SSID {} on {}", ssidConfig.getSsid(), radioIfName); - } - } - - } - } - - } - - private void updateWifiInetConfig(OvsdbClient ovsdbClient, int vlanId, String ifName, boolean enabled, - boolean isNAT, String ifType, String gateway, String inet, Map dns, String ipAssignScheme, - Uuid vifConfigUuid) { - - List operations = new ArrayList<>(); - Map updateColumns = new HashMap<>(); - List conditions = new ArrayList<>(); - conditions.add(new Condition("if_name", Function.EQUALS, new Atom<>(ifName))); - - try { - /// usr/plume/tools/ovsh i Wifi_Inet_Config NAT:=false enabled:=true - /// if_name:=home-ap-24 if_type:=vif ip_assign_scheme:=none - /// network:=true - // dhcpd - updateColumns.put("if_name", new Atom<>(ifName)); - updateColumns.put("if_type", new Atom<>(ifType)); - updateColumns.put("if_uuid", new Atom<>(vifConfigUuid.toString())); - updateColumns.put("enabled", new Atom<>(enabled)); - updateColumns.put("NAT", new Atom<>(isNAT)); - - // mtu // specified in interface, should take that value when - // implemented - updateColumns.put("mtu", new Atom<>(1500)); - updateColumns.put("network", new Atom<>(true)); - - updateColumns.put("ip_assign_scheme", new Atom<>(ipAssignScheme)); - - if (ipAssignScheme.equals("static")) { - updateColumns.put("dns", com.vmware.ovsdb.protocol.operation.notation.Map.of(dns)); - updateColumns.put("inet_addr", new Atom<>(inet)); - updateColumns.put("gateway", new Atom<>(gateway)); - // netmask - // broadcast - } - if (ipAssignScheme.equals("dhcp")) { - updateColumns.put("dhcp_sniff", new Atom<>(true)); - } - else { - updateColumns.put("dhcp_sniff", new Atom<>(false)); - } - - if (ifType.equals("vlan")) { - updateColumns.put("vlan_id", new Atom<>(vlanId)); - } - else { - updateColumns.put("vlan_id", new com.vmware.ovsdb.protocol.operation.notation.Set()); - } - - Row row = new Row(updateColumns); - operations.add(new Update(wifiInetConfigDbTable, conditions, row)); - - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - - LOG.debug("Provisioned WifiInetConfig {}", ifName); - - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - } - - } - catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { - LOG.error("Error in configureWifiInet", e); - throw new RuntimeException(e); - } - - } - - private void insertWifiInetConfigForVif(OvsdbClient ovsdbClient, int vlanId, String ifName, boolean enabled, - boolean isNAT, String ifType, String gateway, String inet, Map dns, String ipAssignScheme, - Uuid vifConfigUuid) { - - List operations = new ArrayList<>(); - Map updateColumns = new HashMap<>(); - - try { - /// usr/plume/tools/ovsh i Wifi_Inet_Config NAT:=false enabled:=true - /// if_name:=home-ap-24 if_type:=vif ip_assign_scheme:=none - /// network:=true - // dhcpd - updateColumns.put("if_name", new Atom<>(ifName)); - updateColumns.put("if_type", new Atom<>(ifType)); - updateColumns.put("if_uuid", new Atom<>(vifConfigUuid.toString())); - updateColumns.put("enabled", new Atom<>(enabled)); - updateColumns.put("NAT", new Atom<>(isNAT)); - - // mtu // specified in interface, should take that value when - // implemented - updateColumns.put("mtu", new Atom<>(1500)); - updateColumns.put("network", new Atom<>(true)); - - updateColumns.put("ip_assign_scheme", new Atom<>(ipAssignScheme)); - - if (ipAssignScheme.equals("static")) { - updateColumns.put("dns", com.vmware.ovsdb.protocol.operation.notation.Map.of(dns)); - updateColumns.put("inet_addr", new Atom<>(inet)); - updateColumns.put("gateway", new Atom<>(gateway)); - // netmask - // broadcast - } - if (ipAssignScheme.equals("dhcp")) { - updateColumns.put("dhcp_sniff", new Atom<>(true)); - } - else { - updateColumns.put("dhcp_sniff", new Atom<>(false)); - } - - if (ifType.equals("vlan")) { - updateColumns.put("vlan_id", new Atom<>(vlanId)); - } - else { - updateColumns.put("vlan_id", new com.vmware.ovsdb.protocol.operation.notation.Set()); - } - - Row row = new Row(updateColumns); - operations.add(new Insert(wifiInetConfigDbTable, row)); - - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - - LOG.debug("Provisioned WifiInetConfig {}", ifName); - - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - } - - } - catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { - LOG.error("Error in configureWifiInet", e); - throw new RuntimeException(e); - } - - } - - public void configureWifiInet(OvsdbClient ovsdbClient, Map provisionedWifiInetConfigs, - String ifName) { - List operations = new ArrayList<>(); - Map updateColumns = new HashMap<>(); - - try { - /// usr/plume/tools/ovsh i Wifi_Inet_Config NAT:=false enabled:=true - /// if_name:=home-ap-24 if_type:=vif ip_assign_scheme:=none - /// network:=true - - updateColumns.put("NAT", new Atom<>(false)); - updateColumns.put("enabled", new Atom<>(true)); - updateColumns.put("if_name", new Atom<>(ifName)); - updateColumns.put("if_type", new Atom<>("vif")); - updateColumns.put("ip_assign_scheme", new Atom<>("none")); - updateColumns.put("network", new Atom<>(true)); - - Row row = new Row(updateColumns); - operations.add(new Insert(wifiInetConfigDbTable, row)); - - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - - LOG.debug("Provisioned WifiInetConfig {}", ifName); - - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - } - - } - catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { - LOG.error("Error in configureWifiInet", e); - throw new RuntimeException(e); - } - - } - - public void configureWifiInetSetNetwork(OvsdbClient ovsdbClient, String ifName) { - List operations = new ArrayList<>(); - Map updateColumns = new HashMap<>(); - List conditions = new ArrayList<>(); - - try { - /// usr/plume/tools/ovsh u Wifi_Inet_Config -w if_name=="br-home" - /// network:=true - - conditions.add(new Condition("if_name", Function.EQUALS, new Atom<>(ifName))); - updateColumns.put("network", new Atom<>(true)); - - Row row = new Row(updateColumns); - operations.add(new Update(wifiInetConfigDbTable, conditions, row)); - - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - - LOG.debug("Enabled network on WifiInetConfig {}", ifName); - - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - } - - } - catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { - LOG.error("Error in configureWifiInetSetNetwork", e); - throw new RuntimeException(e); - } - - } - - public void configureWifiInet(OvsdbClient ovsdbClient) { - Map provisionedWifiInetConfigs = getProvisionedWifiInetConfigs(ovsdbClient); - LOG.debug("Existing WifiInetConfigs: {}", provisionedWifiInetConfigs.keySet()); + Map provisionedPorts = getProvisionedPorts(ovsdbClient); + LOG.debug("Existing Ports: {}", provisionedPorts.keySet()); - String ifName = ifName2pt4GHz; - if (!provisionedWifiInetConfigs.containsKey(ifName)) { - configureWifiInet(ovsdbClient, provisionedWifiInetConfigs, ifName); - } + Map provisionedBridges = getProvisionedBridges(ovsdbClient); + LOG.debug("Existing Bridges: {}", provisionedBridges.keySet()); - ifName = ifName5GHzL; - if (!provisionedWifiInetConfigs.containsKey(ifName)) { - configureWifiInet(ovsdbClient, provisionedWifiInetConfigs, ifName); - } + Map patchH2wOptions = new HashMap<>(); + patchH2wOptions.put("peer", "patch-w2h"); - ifName = ifName5GHzU; - if (!provisionedWifiInetConfigs.containsKey(ifName)) { - configureWifiInet(ovsdbClient, provisionedWifiInetConfigs, ifName); - } + Map patchW2hOptions = new HashMap<>(); + patchH2wOptions.put("peer", "patch-h2w"); - if (!provisionedWifiInetConfigs.containsKey(brLan) || !provisionedWifiInetConfigs.get(brLan).network) { - // set network flag on brHome in wifiInetConfig table - configureWifiInetSetNetwork(ovsdbClient, brLan); - } - } - - public void configureStats(OvsdbClient ovsdbClient) { + provisionSingleBridgePortInterface(ovsdbClient, patchH2w, bridgeNameVifInterfaces, "patch", patchH2wOptions, + provisionedInterfaces, provisionedPorts, provisionedBridges); + provisionSingleBridgePortInterface(ovsdbClient, patchW2h, brWan, "patch", patchW2hOptions, + provisionedInterfaces, provisionedPorts, provisionedBridges); - try { - List operations = new ArrayList<>(); - Map updateColumns = new HashMap<>(); - Map thresholdMap = new HashMap<>(); - thresholdMap.put("max_delay", 600); - thresholdMap.put("util", 10); - - @SuppressWarnings("unchecked") - com.vmware.ovsdb.protocol.operation.notation.Map thresholds = com.vmware.ovsdb.protocol.operation.notation.Map - .of(thresholdMap); + provisionSingleBridgePortInterface(ovsdbClient, ifName5GHzU, bridgeNameVifInterfaces, "vif", null, + provisionedInterfaces, provisionedPorts, provisionedBridges); + provisionSingleBridgePortInterface(ovsdbClient, ifName5GHzL, bridgeNameVifInterfaces, "vif", null, + provisionedInterfaces, provisionedPorts, provisionedBridges); + provisionSingleBridgePortInterface(ovsdbClient, ifName2pt4GHz, bridgeNameVifInterfaces, "vif", null, + provisionedInterfaces, provisionedPorts, provisionedBridges); + + } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { + LOG.error("Error in provisionBridgePortInterface", e); + throw new RuntimeException(e); + } + + } + + public void removeOnboardingSsids(OvsdbClient ovsdbClient) { + try { + List operations = new ArrayList<>(); + List conditions = new ArrayList<>(); + conditions.add(new Condition("ssid", Function.EQUALS, new Atom<>("opensync.onboard"))); + + operations.add(new Delete(wifiVifConfigDbTable, conditions)); + + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + + if (LOG.isDebugEnabled()) { + LOG.debug("Removed onboarding SSIDs from {}:", wifiVifConfigDbTable); + + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + } + } + + } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { + LOG.error("Error in removeOnboardingSsids", e); + throw new RuntimeException(e); + } + + } + + public void removeAllSsids(OvsdbClient ovsdbClient) { + try { + List operations = new ArrayList<>(); + + operations.add(new Delete(wifiVifConfigDbTable)); + + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + + if (LOG.isDebugEnabled()) { + LOG.debug("Removed all existing SSIDs from {}:", wifiVifConfigDbTable); + + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + } + } + + // Now clean up references in the vif_configs columns + operations = new ArrayList<>(); + Map updateColumns = new HashMap<>(); + Set vifConfigsSet = new HashSet<>(); + com.vmware.ovsdb.protocol.operation.notation.Set vifConfigs = com.vmware.ovsdb.protocol.operation.notation.Set + .of(vifConfigsSet); + updateColumns.put("vif_configs", vifConfigs); + + Row row = new Row(updateColumns); + operations.add(new Update(wifiRadioConfigDbTable, row)); + + fResult = ovsdbClient.transact(ovsdbName, operations); + result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + + if (LOG.isDebugEnabled()) { + LOG.debug("Updated WifiRadioConfig "); + + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + } + } + + LOG.info("Removed all ssids"); + + } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { + LOG.error("Error in removeAllSsids", e); + throw new RuntimeException(e); + } + + } + + public void configureWifiRadios(OvsdbClient ovsdbClient, OpensyncAPConfig opensyncAPConfig) { + + Map provisionedWifiRadios = getProvisionedWifiRadioConfigs(ovsdbClient); + LOG.debug("Existing WifiRadioConfigs: {}", provisionedWifiRadios.keySet()); + + String country = opensyncAPConfig.getCountryCode(); // should be the + // same for all + // radios on this AP + // ;-) + + ApElementConfiguration apElementConfiguration = (ApElementConfiguration) opensyncAPConfig.getCustomerEquipment() + .getDetails(); + + for (RadioType radioType : apElementConfiguration.getRadioMap().keySet()) { + Map hwConfig = new HashMap<>(); + + ElementRadioConfiguration elementRadioConfig = apElementConfiguration.getRadioMap().get(radioType); + int channel = elementRadioConfig.getChannelNumber(); + ChannelBandwidth bandwidth = elementRadioConfig.getChannelBandwidth(); + String ht_mode = null; + switch (bandwidth) { + case is20MHz: + ht_mode = "HT20"; + break; + case is40MHz: + ht_mode = "HT40"; + break; + case is80MHz: + ht_mode = "HT80"; + break; + case is160MHz: + ht_mode = "HT160"; + break; + default: + ht_mode = "HT20"; + } + elementRadioConfig.getAutoChannelSelection(); + + RadioConfiguration radioConfig = apElementConfiguration.getAdvancedRadioMap().get(radioType); + int beaconInterval = radioConfig.getBeaconInterval(); + boolean enabled = radioConfig.getRadioAdminState().equals(StateSetting.enabled); + + int txPower = 0; + if (!elementRadioConfig.getEirpTxPower().isAuto()) { + txPower = elementRadioConfig.getEirpTxPower().getValue(); + } + String configName = null; + switch (radioType) { + case is2dot4GHz: + configName = radioName2pt4GHz; + break; + case is5GHz: + // 802.11h dfs (Dynamic Frequency Selection) aka military and + // weather radar + // avoidance protocol + // Must not be disabled (by law) + // NA for 2.4GHz + hwConfig.put("dfs_enable", "1"); + hwConfig.put("dfs_ignorecac", "0"); + hwConfig.put("dfs_usenol", "1"); + configName = radioName5GHzU; + break; + case is5GHzL: + // 802.11h dfs (Dynamic Frequency Selection) aka military and + // weather radar + // avoidance protocol + // Must not be disabled (by law) + // NA for 2.4GHz + hwConfig.put("dfs_enable", "1"); + hwConfig.put("dfs_ignorecac", "0"); + hwConfig.put("dfs_usenol", "1"); + configName = radioName5GHzL; + break; + case is5GHzU: + // 802.11h dfs (Dynamic Frequency Selection) aka military and + // weather radar + // avoidance protocol + // Must not be disabled (by law) + // NA for 2.4GHz + hwConfig.put("dfs_enable", "1"); + hwConfig.put("dfs_ignorecac", "0"); + hwConfig.put("dfs_usenol", "1"); + configName = radioName5GHzU; + break; + default: // don't know this interface + continue; + + } + + if (configName != null) { + try { + configureWifiRadios(ovsdbClient, configName, provisionedWifiRadios, channel, hwConfig, country, + beaconInterval, enabled, ht_mode, txPower); + } catch (OvsdbClientException e) { + LOG.error("ConfigureWifiRadios failed with OvsdbClient exception.", e); + } catch (TimeoutException e) { + LOG.error("ConfigureWifiRadios failed with Timeout.", e); + + } catch (ExecutionException e) { + LOG.error("ConfigureWifiRadios excecution failed.", e); + + } catch (InterruptedException e) { + LOG.error("ConfigureWifiRadios interrupted.", e); + } + + } + + } + + } + + public List getOpensyncAPRadioState(TableUpdates tableUpdates, String apId, + OvsdbClient ovsdbClient) { + + List ret = new ArrayList<>(); + + try { + + for (Entry tableUpdate : tableUpdates.getTableUpdates().entrySet()) { + + for (Entry rowUpdate : tableUpdate.getValue().getRowUpdates().entrySet()) { + + Row row = rowUpdate.getValue().getNew(); + // Row old = rowUpdate.getOld(); + + if (row != null) { + + OpensyncAPRadioState tableState = new OpensyncAPRadioState(); + + 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 (map.get("channel") != null && map.get("channel").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setChannel(row.getIntegerColumn("channel").intValue()); + } + if (map.get("freq_band") != null && map.get("freq_band").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + String frequencyBand = row.getStringColumn("freq_band"); + switch (frequencyBand) { + case "2.4G": + tableState.setFreqBand(RadioType.is2dot4GHz); + break; + case "5G": + tableState.setFreqBand(RadioType.is5GHz); + break; + case "5GL": + tableState.setFreqBand(RadioType.is5GHzL); + break; + case "5GU": + tableState.setFreqBand(RadioType.is5GHzU); + break; + default: + tableState.setFreqBand(RadioType.UNSUPPORTED); + } + } + if (map.get("if_name") != null && map.get("if_name").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setIfName(row.getStringColumn("if_name")); + } + if (map.get("channel_mode") != null && map.get("channel_mode").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setChannelMode(row.getStringColumn("channel_mode")); + } + if (map.get("country") != null && map.get("country").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setCountry(row.getStringColumn("country")); + } + if (map.get("enabled") != null && map.get("enabled").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setEnabled(row.getBooleanColumn("enabled")); + } + if (map.get("ht_mode") != null && map.get("ht_mode").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setHtMode(row.getStringColumn("ht_mode")); + } + if (map.get("tx_power") != null && map.get("tx_power").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setTxPower(row.getIntegerColumn("tx_power").intValue()); + } + if (map.get("hw_config") != null && map.get("hw_config").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Map.class)) { + tableState.setHwConfig(row.getMapColumn("hw_config")); + } + 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")); + } + if (map.get("allowed_channels") != null) { + + Set allowedChannels = getSet(row, "allowed_channels"); + + Set allowed = new HashSet<>(); + for (Long channel : allowedChannels) { + allowed.add(channel.intValue()); + } + tableState.setAllowedChannels(allowed); + } + + ret.add(tableState); + } + } + } + + ret.stream().forEach(wrs -> { + LOG.debug("Wifi_Radio_State row {}", wrs); + }); + + } catch (Exception e) { + LOG.error("Could not parse update for Wifi_Radio_State", e); + } + + return ret; + } + + public List getOpensyncAPInetState(TableUpdates tableUpdates, String apId, + OvsdbClient ovsdbClient) { + List ret = new ArrayList<>(); + + try { + + for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) { + + for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) { + + Row row = rowUpdate.getNew(); + // Row old = rowUpdate.getOld(); + + if (row != null) { + + OpensyncAPInetState tableState = new OpensyncAPInetState(); + Map map = row.getColumns(); + + if (map.get("NAT") != null && map.get("NAT").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setNat(row.getBooleanColumn("NAT")); + } + if (map.get("enabled") != null && map.get("enabled").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setEnabled(row.getBooleanColumn("enabled")); + } + if (map.get("if_name") != null && map.get("if_name").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setIfName(row.getStringColumn("if_name")); + } + if (map.get("if_type") != null && map.get("if_type").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setIfType(row.getStringColumn("if_type")); + } + if (map.get("ip_assign_scheme") != null && map.get("ip_assign_scheme").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setIpAssignScheme(row.getStringColumn("ip_assign_scheme")); + } + if (map.get("network") != null && map.get("network").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setNetwork(row.getBooleanColumn("network")); + } + if (map.get("hwaddr") != null && map.get("hwaddr").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setHwAddr(row.getStringColumn("hwaddr")); + } + 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")); + } + ret.add(tableState); + } + + } + } + + ret.stream().forEach(wrs -> { + LOG.debug("Wifi_Inet_State row {}", wrs); + }); + + } catch (Exception e) { + LOG.error("Could not parse update for Wifi_Inet_State", e); + } + return ret; + } + + public List getOpensyncAPVIFState(TableUpdates tableUpdates, String apId, + OvsdbClient ovsdbClient) { + List ret = new ArrayList<>(); + try { + + for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) { + + for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) { + + Row row = rowUpdate.getNew(); + // Row old = rowUpdate.getOld(); + + if (row != null) { + + OpensyncAPVIFState tableState = new OpensyncAPVIFState(); + + 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 (map.get("bridge") != null && map.get("bridge").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setBridge(row.getStringColumn("bridge")); + } + if (map.get("btm") != null && map.get("btm").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setBtm(row.getIntegerColumn("btm").intValue()); + } + + if (map.get("channel") != null && map.get("channel").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setChannel(row.getIntegerColumn("channel").intValue()); + } + + if (map.get("enabled") != null && map.get("enabled").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setEnabled(row.getBooleanColumn("enabled")); + } + + if (map.get("group_rekey") != null && map.get("group_rekey").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setGroupRekey(row.getIntegerColumn("group_rekey").intValue()); + } + if (map.get("if_name") != null && map.get("if_name").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setIfName(row.getStringColumn("if_name")); + } + + if (map.get("mode") != null && map.get("mode").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setMode(row.getStringColumn("mode")); + } + + if (map.get("rrm") != null && map.get("rrm").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setRrm(row.getIntegerColumn("rrm").intValue()); + } + if (map.get("ssid") != null && map.get("ssid").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setSsid(row.getStringColumn("ssid")); + } + + if (map.get("ssid_broadcast") != null && map.get("ssid_broadcast").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setSsidBroadcast(row.getStringColumn("ssid_broadcast")); + } + if (map.get("uapsd_enable") != null && map.get("uapsd_enable").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setUapsdEnable(row.getBooleanColumn("uapsd_enable")); + } + if (map.get("vif_radio_idx") != null && map.get("vif_radio_idx").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setVifRadioIdx(row.getIntegerColumn("vif_radio_idx").intValue()); + } + + if (map.get("associated_clients") != null) { + tableState.setAssociatedClients(row.getSetColumn("associated_clients")); + } + + if (map.get("security") != null) { + tableState.setSecurity(row.getMapColumn("security")); + } + + 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")); + } + + ret.add(tableState); + + } + + } + } + + ret.stream().forEach(wrs -> { + LOG.debug("Wifi_VIF_State row {}", wrs); + }); + + } catch (Exception e) { + LOG.error("Could not parse update for Wifi_VIF_State", e); + + } + return ret; + } + + public List getOpensyncWifiAssociatedClients(TableUpdates tableUpdates, String apId, + OvsdbClient ovsdbClient) { + List ret = new ArrayList<>(); + + try { + + for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) { + + for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) { + + Row row = rowUpdate.getNew(); + + if (row != null) { + + 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")); + } + + ret.add(tableState); + + } + } + } + ret.stream().forEach(wrs -> { + LOG.debug("Wifi_Associated_Clients row {}", wrs); + }); + } catch (Exception e) { + LOG.error("Could not get Wifi_Associated_Clients list from table update", e); + } + + return ret; + } + + public OpensyncAWLANNode getOpensyncAWLANNode(TableUpdates tableUpdates, String apId, OvsdbClient ovsdbClient) { + OpensyncAWLANNode tableState = new OpensyncAWLANNode(); + + try { + + for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) { + + for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) { + + Row row = rowUpdate.getNew(); + + if (row != null) { + + Map map = row.getColumns(); + + if (map.get("mqtt_settings") != null) { + tableState.setMqttSettings(row.getMapColumn("mqtt_settings")); + } + if (map.get("mqtt_headers") != null) { + tableState.setMqttHeaders(row.getMapColumn("mqtt_headers")); + } + if (map.get("mqtt_topics") != null) { + tableState.setMqttHeaders(row.getMapColumn("mqtt_topics")); + } + + if (map.get("model") != null && map.get("model").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setModel(row.getStringColumn("model")); + } + if (map.get("sku_number") != null && map.get("sku_number").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setSkuNumber(row.getStringColumn("sku_number")); + } + if (map.get("id") != null && map.get("id").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setId(row.getStringColumn("id")); + } + + if (map.get("version_matrix") != null) { + tableState.setVersionMatrix(row.getMapColumn("version_matrix")); + } + if (map.get("firmware_version") != null && map.get("firmware_version").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setFirmwareVersion(row.getStringColumn("firmware_version")); + } + if (map.get("firmware_url") != null && map.get("firmware_url").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setFirmwareUrl(row.getStringColumn("firmware_url")); + } + + if (map.get("_uuid") != null && map.get("_uuid").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setVersion(row.getUuidColumn("_uuid")); + } + if (map.get("upgrade_dl_timer") != null && map.get("upgrade_dl_timer").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setUpgradeDlTimer(row.getIntegerColumn("upgrade_dl_timer").intValue()); + } + if (map.get("platform_version") != null && map.get("platform_version").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setPlatformVersion(row.getStringColumn("platform_version")); + } + if (map.get("firmware_pass") != null && map.get("firmware_pass").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setFirmwarePass(row.getStringColumn("firmware_pass")); + } + if (map.get("upgrade_timer") != null && map.get("upgrade_timer").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setUpgradeTimer(row.getIntegerColumn("upgrade_timer").intValue()); + } + if (map.get("max_backoff") != null && map.get("max_backoff").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setMaxBackoff(row.getIntegerColumn("max_backoff").intValue()); + } + if (map.get("led_config") != null) { + tableState.setLedConfig(row.getMapColumn("led_config")); + } + if (map.get("redirector_addr") != null && map.get("redirector_addr").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setRedirectorAddr(row.getStringColumn("redirector_addr")); + } + if (map.get("serial_number") != null && map.get("serial_number").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setSerialNumber(row.getStringColumn("serial_number")); + } + 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("upgrade_status") != null && map.get("upgrade_status").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setUpgradeTimer(row.getIntegerColumn("upgrade_status").intValue()); + } + if (map.get("device_mode") != null && map.get("device_mode").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setDeviceMode(row.getStringColumn("device_mode")); + } + if (map.get("min_backoff") != null && map.get("min_backoff").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setMinBackoff(row.getIntegerColumn("min_backoff").intValue()); + } + + if (map.get("revision") != null && map.get("revision").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setRevision(row.getStringColumn("revision")); + } + if (map.get("manager_addr") != null && map.get("manager_addr").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setManagerAddr(row.getStringColumn("manager_addr")); + } + if (map.get("factory_reset") != null && map.get("factory_reset").getClass() + .equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { + tableState.setFactoryReset(row.getBooleanColumn("factory_reset")); + } + } + + } + + } + } catch (Exception e) { + LOG.error("Failed to handle AWLAN_Node update", e); + } + + return tableState; + + } + + public void configureWifiRadios(OvsdbClient ovsdbClient, String configName, + Map provisionedWifiRadios, int channel, Map hwConfig, + String country, int beaconInterval, boolean enabled, String ht_mode, int txPower) + throws OvsdbClientException, TimeoutException, ExecutionException, InterruptedException { + + WifiRadioConfigInfo existingConfig = provisionedWifiRadios.get(configName); + + if (existingConfig == null) { + LOG.warn("There is no WifiRadioConfig {}", configName); + return; + } + + List operations = new ArrayList<>(); + Map updateColumns = new HashMap<>(); + List conditions = new ArrayList<>(); + conditions.add(new Condition("if_name", Function.EQUALS, new Atom<>(configName))); + + updateColumns.put("channel", new Atom<>(channel)); + updateColumns.put("country", new Atom<>(country)); + @SuppressWarnings("unchecked") + com.vmware.ovsdb.protocol.operation.notation.Map hwConfigMap = com.vmware.ovsdb.protocol.operation.notation.Map + .of(hwConfig); + updateColumns.put("hw_config", hwConfigMap); + updateColumns.put("bcn_int", new Atom<>(beaconInterval)); + updateColumns.put("enabled", new Atom<>(enabled)); + updateColumns.put("ht_mode", new Atom<>(ht_mode)); + if (txPower > 0) { + updateColumns.put("tx_power", new Atom<>(txPower)); + } else { + updateColumns.put("tx_power", new com.vmware.ovsdb.protocol.operation.notation.Set()); + } + + Row row = new Row(updateColumns); + operations.add(new Update(wifiRadioConfigDbTable, conditions, row)); + + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + + LOG.debug("Provisioned channel {} for {}", channel, configName); + + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + } + } + + public void configureSingleSsid(OvsdbClient ovsdbClient, String bridge, String ifName, String ssid, + boolean ssidBroadcast, Map security, + Map provisionedWifiRadioConfigs, String radioIfName, int vlanId, + boolean rrmEnabled, String minHwMode, boolean enabled, int keyRefresh, boolean uapsdEnabled, + boolean apBridge, NetworkForwardMode networkForwardMode, String gateway, String inet, + Map dns, String ipAssignScheme) { + + List operations = new ArrayList<>(); + Map updateColumns = new HashMap<>(); + + try { + updateColumns.put("bridge", new Atom(bridge)); + updateColumns.put("btm", new Atom<>(1)); + updateColumns.put("enabled", new Atom<>(enabled)); + updateColumns.put("ft_psk", new Atom<>(0)); + updateColumns.put("if_name", new Atom<>(ifName)); + updateColumns.put("mode", new Atom<>("ap")); + updateColumns.put("rrm", new Atom<>(rrmEnabled ? 1 : 0)); + updateColumns.put("ssid", new Atom<>(ssid)); + updateColumns.put("ssid_broadcast", new Atom<>(ssidBroadcast ? "enabled" : "disabled")); + updateColumns.put("uapsd_enable", new Atom<>(true)); + // updateColumns.put("vif_radio_idx", new + // Atom(vifRadioIdx)); + updateColumns.put("min_hw_mode", new Atom<>(minHwMode)); + updateColumns.put("vlan_id", new Atom<>(vlanId)); + 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 securityMap = com.vmware.ovsdb.protocol.operation.notation.Map + .of(security); + updateColumns.put("security", securityMap); + + Row row = new Row(updateColumns); + operations.add(new Insert(wifiVifConfigDbTable, row)); + + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + + LOG.debug("Provisioned SSID {} on {}", ssid, ifName); + + Uuid vifConfigUuid = null; + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + if (res instanceof InsertResult) { + vifConfigUuid = ((InsertResult) res).getUuid(); + } + } + + if (vifConfigUuid == null) { + throw new IllegalStateException("Wifi_VIF_Config entry was not created successfully"); + } + + // update Wifi_Radio_Config here - add vifConfigUuid + /// usr/plume/tools/ovsh u Wifi_Radio_Config + // vif_configs:='["set",[["uuid","98e42897-b567-4186-84a6-4a4e38a51e9d"],["uuid","4314920e-c4e6-42a6-93e3-261142ed9adf"]]]' + // --where if_name==wifi0 + updateColumns.clear(); + operations.clear(); + + WifiRadioConfigInfo wifiRadioConfigInfo = provisionedWifiRadioConfigs.get(radioIfName); + if (wifiRadioConfigInfo == null) { + throw new IllegalStateException("missing Wifi_Radio_Config entry " + radioIfName); + } + + Set vifConfigsSet = new HashSet<>(wifiRadioConfigInfo.vifConfigUuids); + vifConfigsSet.add(vifConfigUuid); + com.vmware.ovsdb.protocol.operation.notation.Set vifConfigs = com.vmware.ovsdb.protocol.operation.notation.Set + .of(vifConfigsSet); + updateColumns.put("vif_configs", vifConfigs); + + List conditions = new ArrayList<>(); + conditions.add(new Condition("if_name", Function.EQUALS, new Atom<>(radioIfName))); + + row = new Row(updateColumns); + operations.add(new Update(wifiRadioConfigDbTable, conditions, row)); + + fResult = ovsdbClient.transact(ovsdbName, operations); + result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + + if (LOG.isDebugEnabled()) { + LOG.debug("Updated WifiRadioConfig {} for SSID {}:", radioIfName, ssid); + + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + } + } + Map inetConfigs = getProvisionedWifiInetConfigs(ovsdbClient); + if (inetConfigs.containsKey(ifName)) { + updateWifiInetConfig(ovsdbClient, vlanId, ifName, enabled, networkForwardMode == NetworkForwardMode.NAT, + "vif", gateway, inet, dns, ipAssignScheme, vifConfigUuid); + } else { + LOG.debug("No corresponding WifiInetConfig for this Interface"); + insertWifiInetConfigForVif(ovsdbClient, vlanId, ifName, enabled, + networkForwardMode == NetworkForwardMode.NAT, "vif", gateway, inet, dns, ipAssignScheme, + vifConfigUuid); + } + + LOG.info("Provisioned SSID {} on interface {} / {}", ssid, ifName, radioIfName); + + } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { + LOG.error("Error in configureSingleSsid", e); + throw new RuntimeException(e); + } + } + + public void configureSsids(OvsdbClient ovsdbClient, OpensyncAPConfig opensyncApConfig) { + + boolean rrmEnabled = false; + if (opensyncApConfig.getEquipmentLocation() != null + && opensyncApConfig.getEquipmentLocation().getDetails() != null) { + rrmEnabled = opensyncApConfig.getEquipmentLocation().getDetails().isRrmEnabled(); + } + + for (Profile ssidProfile : opensyncApConfig.getSsidProfile()) { + + Map provisionedWifiVifConfigs = getProvisionedWifiVifConfigs(ovsdbClient); + LOG.debug("Existing WifiVifConfigs: {}", provisionedWifiVifConfigs.keySet()); + + SsidConfiguration ssidConfig = (SsidConfiguration) ssidProfile.getDetails(); + ApElementConfiguration apElementConfig = (ApElementConfiguration) opensyncApConfig.getCustomerEquipment() + .getDetails(); + for (RadioType radioType : ssidConfig.getAppliedRadios()) { + + int keyRefresh = ssidConfig.getKeyRefresh(); + + Map provisionedWifiRadioConfigs = getProvisionedWifiRadioConfigs( + ovsdbClient); + + boolean ssidBroadcast = ssidConfig.getBroadcastSsid() == StateSetting.enabled; + Map security = new HashMap<>(); + String ssidSecurityMode = ssidConfig.getSecureMode().name(); + String opensyncSecurityMode = "OPEN"; + + String ipAssignScheme = "none"; + // the following 5 attributes only applicable to static config, + // else they are + // ignored + String gateway = null; + String inet = null; + Map dns = null; + 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 if (apElementConfig.getGettingIP().equals(GettingIP.dhcp) + || apElementConfig.getGettingDNS().equals(GettingDNS.dhcp)) { + ipAssignScheme = "dhcp"; + } + + RadioConfiguration radioConfiguration = apElementConfig.getAdvancedRadioMap().get(radioType); + if (radioConfiguration == null) { + continue; // don't have a radio of this kind in the map + } + RadioMode radioMode = radioConfiguration.getRadioMode(); + + boolean uapsdEnabled = radioConfiguration.getUapsdState() == StateSetting.enabled; + + boolean apBridge = radioConfiguration.getStationIsolation() == StateSetting.enabled; // stationIsolation + + String minHwMode = "11n"; // min_hw_mode is 11ac, wifi 5, we can + // also take ++ (11ax) but 2.4GHz only + // Wifi4 -- + if (!radioType.equals(RadioType.is2dot4GHz)) { + minHwMode = "11ac"; + } + if (!radioType.equals(RadioType.is2dot4GHz) && radioMode.equals(RadioMode.modeX)) { + minHwMode = "11x"; + } + + if (ssidSecurityMode.equals("wpaPSK") || ssidSecurityMode.equals("wpa2PSK")) { + opensyncSecurityMode = "WPA-PSK"; + } else if (ssidSecurityMode.equals("wep")) { + opensyncSecurityMode = "WEP"; + } else if (ssidSecurityMode.equals("wepEAP")) { + opensyncSecurityMode = "WEP-EAP"; + } + + security.put("encryption", opensyncSecurityMode); + // key and mode is N/A for OPEN security + if (!opensyncSecurityMode.equals("OPEN")) { + security.put("key", ssidConfig.getKeyStr()); + if (ssidSecurityMode.equals("wpa2PSK") || ssidSecurityMode.equals("wepEAP") + || ssidSecurityMode.equals("wpa2OnlyPSK")) { + security.put("mode", "2"); + } else { + security.put("mode", "1"); + } + } + + boolean enabled = ssidConfig.getSsidAdminState().equals(StateSetting.enabled); + + String ifName = null; + String radioIfName = null; + + if (radioType == RadioType.is2dot4GHz) { + ifName = ifName2pt4GHz; + radioIfName = radioName2pt4GHz; + } else if (radioType == RadioType.is5GHzL) { + ifName = ifName5GHzL; + radioIfName = radioName5GHzL; + } else if (radioType == RadioType.is5GHzU) { + ifName = ifName5GHzU; + radioIfName = radioName5GHzU; + } + + if (!provisionedWifiVifConfigs.containsKey(ifName + "_" + ssidConfig.getSsid())) { + try { + configureSingleSsid(ovsdbClient, bridgeNameVifInterfaces, ifName, ssidConfig.getSsid(), + ssidBroadcast, security, provisionedWifiRadioConfigs, radioIfName, + ssidConfig.getVlanId(), rrmEnabled, minHwMode, enabled, keyRefresh, uapsdEnabled, + apBridge, ssidConfig.getForwardMode(), gateway, inet, dns, ipAssignScheme); + + } catch (IllegalStateException e) { + // could not provision this SSID, but still can go on + LOG.warn("could not provision SSID {} on {}", ssidConfig.getSsid(), radioIfName); + } + } + + } + } + + } + + private void updateWifiInetConfig(OvsdbClient ovsdbClient, int vlanId, String ifName, boolean enabled, + boolean isNAT, String ifType, String gateway, String inet, Map dns, String ipAssignScheme, + Uuid vifConfigUuid) { + + List operations = new ArrayList<>(); + Map updateColumns = new HashMap<>(); + List conditions = new ArrayList<>(); + conditions.add(new Condition("if_name", Function.EQUALS, new Atom<>(ifName))); + + try { + /// usr/plume/tools/ovsh i Wifi_Inet_Config NAT:=false enabled:=true + /// if_name:=home-ap-24 if_type:=vif ip_assign_scheme:=none + /// network:=true + // dhcpd + updateColumns.put("if_name", new Atom<>(ifName)); + updateColumns.put("if_type", new Atom<>(ifType)); + updateColumns.put("if_uuid", new Atom<>(vifConfigUuid.toString())); + updateColumns.put("enabled", new Atom<>(enabled)); + updateColumns.put("NAT", new Atom<>(isNAT)); + + // mtu // specified in interface, should take that value when + // implemented + updateColumns.put("mtu", new Atom<>(1500)); + updateColumns.put("network", new Atom<>(true)); + + updateColumns.put("ip_assign_scheme", new Atom<>(ipAssignScheme)); + + if (ipAssignScheme.equals("static")) { + updateColumns.put("dns", com.vmware.ovsdb.protocol.operation.notation.Map.of(dns)); + updateColumns.put("inet_addr", new Atom<>(inet)); + updateColumns.put("gateway", new Atom<>(gateway)); + // netmask + // broadcast + } + if (ipAssignScheme.equals("dhcp")) { + updateColumns.put("dhcp_sniff", new Atom<>(true)); + } else { + updateColumns.put("dhcp_sniff", new Atom<>(false)); + } + + if (ifType.equals("vlan")) { + updateColumns.put("vlan_id", new Atom<>(vlanId)); + } else { + updateColumns.put("vlan_id", new com.vmware.ovsdb.protocol.operation.notation.Set()); + } + + Row row = new Row(updateColumns); + operations.add(new Update(wifiInetConfigDbTable, conditions, row)); + + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + + LOG.debug("Provisioned WifiInetConfig {}", ifName); + + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + } + + } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { + LOG.error("Error in configureWifiInet", e); + throw new RuntimeException(e); + } + + } + + private void insertWifiInetConfigForVif(OvsdbClient ovsdbClient, int vlanId, String ifName, boolean enabled, + boolean isNAT, String ifType, String gateway, String inet, Map dns, String ipAssignScheme, + Uuid vifConfigUuid) { + + List operations = new ArrayList<>(); + Map updateColumns = new HashMap<>(); + + try { + /// usr/plume/tools/ovsh i Wifi_Inet_Config NAT:=false enabled:=true + /// if_name:=home-ap-24 if_type:=vif ip_assign_scheme:=none + /// network:=true + // dhcpd + updateColumns.put("if_name", new Atom<>(ifName)); + updateColumns.put("if_type", new Atom<>(ifType)); + updateColumns.put("if_uuid", new Atom<>(vifConfigUuid.toString())); + updateColumns.put("enabled", new Atom<>(enabled)); + updateColumns.put("NAT", new Atom<>(isNAT)); + + // mtu // specified in interface, should take that value when + // implemented + updateColumns.put("mtu", new Atom<>(1500)); + updateColumns.put("network", new Atom<>(true)); + + updateColumns.put("ip_assign_scheme", new Atom<>(ipAssignScheme)); + + if (ipAssignScheme.equals("static")) { + updateColumns.put("dns", com.vmware.ovsdb.protocol.operation.notation.Map.of(dns)); + updateColumns.put("inet_addr", new Atom<>(inet)); + updateColumns.put("gateway", new Atom<>(gateway)); + // netmask + // broadcast + } + if (ipAssignScheme.equals("dhcp")) { + updateColumns.put("dhcp_sniff", new Atom<>(true)); + } else { + updateColumns.put("dhcp_sniff", new Atom<>(false)); + } + + if (ifType.equals("vlan")) { + updateColumns.put("vlan_id", new Atom<>(vlanId)); + } else { + updateColumns.put("vlan_id", new com.vmware.ovsdb.protocol.operation.notation.Set()); + } + + Row row = new Row(updateColumns); + operations.add(new Insert(wifiInetConfigDbTable, row)); + + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + + LOG.debug("Provisioned WifiInetConfig {}", ifName); + + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + } + + } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { + LOG.error("Error in configureWifiInet", e); + throw new RuntimeException(e); + } + + } + + public void configureWifiInet(OvsdbClient ovsdbClient, Map provisionedWifiInetConfigs, + String ifName) { + List operations = new ArrayList<>(); + Map updateColumns = new HashMap<>(); + + try { + /// usr/plume/tools/ovsh i Wifi_Inet_Config NAT:=false enabled:=true + /// if_name:=home-ap-24 if_type:=vif ip_assign_scheme:=none + /// network:=true + + updateColumns.put("NAT", new Atom<>(false)); + updateColumns.put("enabled", new Atom<>(true)); + updateColumns.put("if_name", new Atom<>(ifName)); + updateColumns.put("if_type", new Atom<>("vif")); + updateColumns.put("ip_assign_scheme", new Atom<>("none")); + updateColumns.put("network", new Atom<>(true)); + + Row row = new Row(updateColumns); + operations.add(new Insert(wifiInetConfigDbTable, row)); + + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + + LOG.debug("Provisioned WifiInetConfig {}", ifName); + + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + } + + } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { + LOG.error("Error in configureWifiInet", e); + throw new RuntimeException(e); + } + + } + + public void configureWifiInetSetNetwork(OvsdbClient ovsdbClient, String ifName) { + List operations = new ArrayList<>(); + Map updateColumns = new HashMap<>(); + List conditions = new ArrayList<>(); + + try { + /// usr/plume/tools/ovsh u Wifi_Inet_Config -w if_name=="br-home" + /// network:=true + + conditions.add(new Condition("if_name", Function.EQUALS, new Atom<>(ifName))); + updateColumns.put("network", new Atom<>(true)); + + Row row = new Row(updateColumns); + operations.add(new Update(wifiInetConfigDbTable, conditions, row)); + + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + + LOG.debug("Enabled network on WifiInetConfig {}", ifName); + + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + } + + } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { + LOG.error("Error in configureWifiInetSetNetwork", e); + throw new RuntimeException(e); + } + + } + + public void configureWifiInet(OvsdbClient ovsdbClient) { + Map provisionedWifiInetConfigs = getProvisionedWifiInetConfigs(ovsdbClient); + LOG.debug("Existing WifiInetConfigs: {}", provisionedWifiInetConfigs.keySet()); + + String ifName = ifName2pt4GHz; + if (!provisionedWifiInetConfigs.containsKey(ifName)) { + configureWifiInet(ovsdbClient, provisionedWifiInetConfigs, ifName); + } + + ifName = ifName5GHzL; + if (!provisionedWifiInetConfigs.containsKey(ifName)) { + configureWifiInet(ovsdbClient, provisionedWifiInetConfigs, ifName); + } + + ifName = ifName5GHzU; + if (!provisionedWifiInetConfigs.containsKey(ifName)) { + configureWifiInet(ovsdbClient, provisionedWifiInetConfigs, ifName); + } + + if (!provisionedWifiInetConfigs.containsKey(brLan) || !provisionedWifiInetConfigs.get(brLan).network) { + // set network flag on brHome in wifiInetConfig table + configureWifiInetSetNetwork(ovsdbClient, brLan); + } + } + + public void configureStats(OvsdbClient ovsdbClient) { + + try { + List operations = new ArrayList<>(); + Map updateColumns = new HashMap<>(); + Map thresholdMap = new HashMap<>(); + thresholdMap.put("max_delay", 600); + thresholdMap.put("util", 10); + + @SuppressWarnings("unchecked") + com.vmware.ovsdb.protocol.operation.notation.Map thresholds = com.vmware.ovsdb.protocol.operation.notation.Map + .of(thresholdMap); // provisionWifiStatsConfigDevice(getProvisionedWifiStatsConfigs(ovsdbClient), operations, updateColumns); - provisionWifiStatsConfigSurvey(getProvisionedWifiStatsConfigs(ovsdbClient), operations, thresholds); + provisionWifiStatsConfigSurvey(getProvisionedWifiStatsConfigs(ovsdbClient), operations, thresholds); - provisionWifiStatsConfigNeighbor(getProvisionedWifiStatsConfigs(ovsdbClient), operations); + provisionWifiStatsConfigNeighbor(getProvisionedWifiStatsConfigs(ovsdbClient), operations); - provisionWifiStatsConfigClient(getProvisionedWifiStatsConfigs(ovsdbClient), operations); + provisionWifiStatsConfigClient(getProvisionedWifiStatsConfigs(ovsdbClient), operations); - provisionWifiStatsRssi(getProvisionedWifiStatsConfigs(ovsdbClient), operations); + provisionWifiStatsRssi(getProvisionedWifiStatsConfigs(ovsdbClient), operations); - if (!operations.isEmpty()) { - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + if (!operations.isEmpty()) { + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - if (LOG.isDebugEnabled()) { - LOG.debug("Updated {}:", wifiStatsConfigDbTable); + if (LOG.isDebugEnabled()) { + LOG.debug("Updated {}:", wifiStatsConfigDbTable); - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - } - } - } + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + } + } + } - } - catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { - throw new RuntimeException(e); - } - } + } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { + throw new RuntimeException(e); + } + } - private void provisionWifiStatsRssi(Map provisionedWifiStatsConfigs, - List operations) { - Map updateColumns; - Row row; - for (String band : new String[] { "2.4G", "5GL", "5GU" }) { - if (!provisionedWifiStatsConfigs.containsKey(band + "_rssi_on-chan")) { - updateColumns = new HashMap<>(); - updateColumns.put("radio_type", new Atom<>(band)); - updateColumns.put("reporting_count", new Atom<>(0)); - updateColumns.put("reporting_interval", new Atom<>(60)); - updateColumns.put("sampling_interval", new Atom<>(10)); - updateColumns.put("stats_type", new Atom<>("rssi")); - updateColumns.put("survey_interval_ms", new Atom<>(0)); - updateColumns.put("survey_type", new Atom<>("on-chan")); - row = new Row(updateColumns); + private void provisionWifiStatsRssi(Map provisionedWifiStatsConfigs, + List operations) { + Map updateColumns; + Row row; + for (String band : new String[] { "2.4G", "5GL", "5GU" }) { + if (!provisionedWifiStatsConfigs.containsKey(band + "_rssi_on-chan")) { + updateColumns = new HashMap<>(); + updateColumns.put("radio_type", new Atom<>(band)); + updateColumns.put("reporting_count", new Atom<>(0)); + updateColumns.put("reporting_interval", new Atom<>(60)); + updateColumns.put("sampling_interval", new Atom<>(10)); + updateColumns.put("stats_type", new Atom<>("rssi")); + updateColumns.put("survey_interval_ms", new Atom<>(0)); + updateColumns.put("survey_type", new Atom<>("on-chan")); + row = new Row(updateColumns); - operations.add(new Insert(wifiStatsConfigDbTable, row)); - } + operations.add(new Insert(wifiStatsConfigDbTable, row)); + } - } - } + } + } - private void provisionWifiStatsConfigNeighbor(Map provisionedWifiStatsConfigs, - List operations) { - Map updateColumns; - Row row; + private void provisionWifiStatsConfigNeighbor(Map provisionedWifiStatsConfigs, + List operations) { + Map updateColumns; + Row row; - Set channelSet2g = new HashSet<>(); - channelSet2g.add(1); - channelSet2g.add(6); - channelSet2g.add(11); - com.vmware.ovsdb.protocol.operation.notation.Set channels2g = com.vmware.ovsdb.protocol.operation.notation.Set - .of(channelSet2g); + Set channelSet2g = new HashSet<>(); + channelSet2g.add(1); + channelSet2g.add(6); + channelSet2g.add(11); + com.vmware.ovsdb.protocol.operation.notation.Set channels2g = com.vmware.ovsdb.protocol.operation.notation.Set + .of(channelSet2g); - Set channelSet5gl = new HashSet<>(); - channelSet5gl.add(36); - channelSet5gl.add(44); - channelSet5gl.add(52); - com.vmware.ovsdb.protocol.operation.notation.Set channels5gl = com.vmware.ovsdb.protocol.operation.notation.Set - .of(channelSet5gl); + Set channelSet5gl = new HashSet<>(); + channelSet5gl.add(36); + channelSet5gl.add(44); + channelSet5gl.add(52); + com.vmware.ovsdb.protocol.operation.notation.Set channels5gl = com.vmware.ovsdb.protocol.operation.notation.Set + .of(channelSet5gl); - Set channelSet5gu = new HashSet<>(); - channelSet5gu.add(100); - channelSet5gu.add(108); - channelSet5gu.add(116); - com.vmware.ovsdb.protocol.operation.notation.Set channels5gu = com.vmware.ovsdb.protocol.operation.notation.Set - .of(channelSet5gu); + Set channelSet5gu = new HashSet<>(); + channelSet5gu.add(100); + channelSet5gu.add(108); + channelSet5gu.add(116); + com.vmware.ovsdb.protocol.operation.notation.Set channels5gu = com.vmware.ovsdb.protocol.operation.notation.Set + .of(channelSet5gu); - if (!provisionedWifiStatsConfigs.containsKey("2.4G_neighbor_off-chan")) { + if (!provisionedWifiStatsConfigs.containsKey("2.4G_neighbor_off-chan")) { - updateColumns = new HashMap<>(); - updateColumns.put("channel_list", channels2g); - updateColumns.put("radio_type", new Atom<>("2.4G")); - updateColumns.put("reporting_interval", new Atom<>(120)); - updateColumns.put("sampling_interval", new Atom<>(0)); - updateColumns.put("stats_type", new Atom<>("neighbor")); - updateColumns.put("survey_interval_ms", new Atom<>(0)); - updateColumns.put("survey_type", new Atom<>("off-chan")); - // updateColumns.put("threshold", thresholds ); + updateColumns = new HashMap<>(); + updateColumns.put("channel_list", channels2g); + updateColumns.put("radio_type", new Atom<>("2.4G")); + updateColumns.put("reporting_interval", new Atom<>(120)); + updateColumns.put("sampling_interval", new Atom<>(0)); + updateColumns.put("stats_type", new Atom<>("neighbor")); + updateColumns.put("survey_interval_ms", new Atom<>(0)); + updateColumns.put("survey_type", new Atom<>("off-chan")); + // updateColumns.put("threshold", thresholds ); - row = new Row(updateColumns); - operations.add(new Insert(wifiStatsConfigDbTable, row)); + row = new Row(updateColumns); + operations.add(new Insert(wifiStatsConfigDbTable, row)); - } + } - if (!provisionedWifiStatsConfigs.containsKey("5GL_neighbor_off-chan")) { + if (!provisionedWifiStatsConfigs.containsKey("5GL_neighbor_off-chan")) { - updateColumns = new HashMap<>(); - updateColumns.put("channel_list", channels5gl); - updateColumns.put("radio_type", new Atom<>("5GL")); - updateColumns.put("reporting_interval", new Atom<>(120)); - updateColumns.put("sampling_interval", new Atom<>(0)); - updateColumns.put("stats_type", new Atom<>("neighbor")); - updateColumns.put("survey_interval_ms", new Atom<>(0)); - updateColumns.put("survey_type", new Atom<>("off-chan")); - // updateColumns.put("threshold", thresholds ); + updateColumns = new HashMap<>(); + updateColumns.put("channel_list", channels5gl); + updateColumns.put("radio_type", new Atom<>("5GL")); + updateColumns.put("reporting_interval", new Atom<>(120)); + updateColumns.put("sampling_interval", new Atom<>(0)); + updateColumns.put("stats_type", new Atom<>("neighbor")); + updateColumns.put("survey_interval_ms", new Atom<>(0)); + updateColumns.put("survey_type", new Atom<>("off-chan")); + // updateColumns.put("threshold", thresholds ); - row = new Row(updateColumns); - operations.add(new Insert(wifiStatsConfigDbTable, row)); + row = new Row(updateColumns); + operations.add(new Insert(wifiStatsConfigDbTable, row)); - } + } - if (!provisionedWifiStatsConfigs.containsKey("5GU_neighbor_off-chan")) { + if (!provisionedWifiStatsConfigs.containsKey("5GU_neighbor_off-chan")) { - updateColumns = new HashMap<>(); - updateColumns.put("channel_list", channels5gu); - updateColumns.put("radio_type", new Atom<>("5GU")); - updateColumns.put("reporting_interval", new Atom<>(120)); - updateColumns.put("sampling_interval", new Atom<>(0)); - updateColumns.put("stats_type", new Atom<>("neighbor")); - updateColumns.put("survey_interval_ms", new Atom<>(0)); - updateColumns.put("survey_type", new Atom<>("off-chan")); - // updateColumns.put("threshold", thresholds ); + updateColumns = new HashMap<>(); + updateColumns.put("channel_list", channels5gu); + updateColumns.put("radio_type", new Atom<>("5GU")); + updateColumns.put("reporting_interval", new Atom<>(120)); + updateColumns.put("sampling_interval", new Atom<>(0)); + updateColumns.put("stats_type", new Atom<>("neighbor")); + updateColumns.put("survey_interval_ms", new Atom<>(0)); + updateColumns.put("survey_type", new Atom<>("off-chan")); + // updateColumns.put("threshold", thresholds ); - row = new Row(updateColumns); - operations.add(new Insert(wifiStatsConfigDbTable, row)); + row = new Row(updateColumns); + operations.add(new Insert(wifiStatsConfigDbTable, row)); - } + } - if (!provisionedWifiStatsConfigs.containsKey("5GU_neighbor_on-chan")) { - // - updateColumns = new HashMap<>(); - // updateColumns.put("channel_list", channels ); - updateColumns.put("radio_type", new Atom<>("5GU")); - updateColumns.put("reporting_interval", new Atom<>(60)); - updateColumns.put("sampling_interval", new Atom<>(0)); - updateColumns.put("stats_type", new Atom<>("neighbor")); - updateColumns.put("survey_interval_ms", new Atom<>(0)); - updateColumns.put("survey_type", new Atom<>("on-chan")); - // updateColumns.put("threshold", thresholds ); + if (!provisionedWifiStatsConfigs.containsKey("5GU_neighbor_on-chan")) { + // + updateColumns = new HashMap<>(); + // updateColumns.put("channel_list", channels ); + updateColumns.put("radio_type", new Atom<>("5GU")); + updateColumns.put("reporting_interval", new Atom<>(60)); + updateColumns.put("sampling_interval", new Atom<>(0)); + updateColumns.put("stats_type", new Atom<>("neighbor")); + updateColumns.put("survey_interval_ms", new Atom<>(0)); + updateColumns.put("survey_type", new Atom<>("on-chan")); + // updateColumns.put("threshold", thresholds ); - row = new Row(updateColumns); - operations.add(new Insert(wifiStatsConfigDbTable, row)); - // - } + row = new Row(updateColumns); + operations.add(new Insert(wifiStatsConfigDbTable, row)); + // + } - if (!provisionedWifiStatsConfigs.containsKey("5GL_neighbor_on-chan")) { - // - updateColumns = new HashMap<>(); - // updateColumns.put("channel_list", channels ); - updateColumns.put("radio_type", new Atom<>("5GL")); - updateColumns.put("reporting_interval", new Atom<>(60)); - updateColumns.put("sampling_interval", new Atom<>(0)); - updateColumns.put("stats_type", new Atom<>("neighbor")); - updateColumns.put("survey_interval_ms", new Atom<>(0)); - updateColumns.put("survey_type", new Atom<>("on-chan")); - // updateColumns.put("threshold", thresholds ); + if (!provisionedWifiStatsConfigs.containsKey("5GL_neighbor_on-chan")) { + // + updateColumns = new HashMap<>(); + // updateColumns.put("channel_list", channels ); + updateColumns.put("radio_type", new Atom<>("5GL")); + updateColumns.put("reporting_interval", new Atom<>(60)); + updateColumns.put("sampling_interval", new Atom<>(0)); + updateColumns.put("stats_type", new Atom<>("neighbor")); + updateColumns.put("survey_interval_ms", new Atom<>(0)); + updateColumns.put("survey_type", new Atom<>("on-chan")); + // updateColumns.put("threshold", thresholds ); - row = new Row(updateColumns); - operations.add(new Insert(wifiStatsConfigDbTable, row)); - // - } + row = new Row(updateColumns); + operations.add(new Insert(wifiStatsConfigDbTable, row)); + // + } - if (!provisionedWifiStatsConfigs.containsKey("2.4G_neighbor_on-chan")) { - // - updateColumns = new HashMap<>(); - // updateColumns.put("channel_list", channels ); - updateColumns.put("radio_type", new Atom<>("2.4G")); - updateColumns.put("reporting_interval", new Atom<>(60)); - updateColumns.put("sampling_interval", new Atom<>(0)); - updateColumns.put("stats_type", new Atom<>("neighbor")); - updateColumns.put("survey_interval_ms", new Atom<>(0)); - updateColumns.put("survey_type", new Atom<>("on-chan")); - // updateColumns.put("threshold", thresholds ); + if (!provisionedWifiStatsConfigs.containsKey("2.4G_neighbor_on-chan")) { + // + updateColumns = new HashMap<>(); + // updateColumns.put("channel_list", channels ); + updateColumns.put("radio_type", new Atom<>("2.4G")); + updateColumns.put("reporting_interval", new Atom<>(60)); + updateColumns.put("sampling_interval", new Atom<>(0)); + updateColumns.put("stats_type", new Atom<>("neighbor")); + updateColumns.put("survey_interval_ms", new Atom<>(0)); + updateColumns.put("survey_type", new Atom<>("on-chan")); + // updateColumns.put("threshold", thresholds ); - row = new Row(updateColumns); - operations.add(new Insert(wifiStatsConfigDbTable, row)); - // - } - } + row = new Row(updateColumns); + operations.add(new Insert(wifiStatsConfigDbTable, row)); + // + } + } - private void provisionWifiStatsConfigSurvey(Map provisionedWifiStatsConfigs, - List operations, com.vmware.ovsdb.protocol.operation.notation.Map thresholds) { + private void provisionWifiStatsConfigSurvey(Map provisionedWifiStatsConfigs, + List operations, com.vmware.ovsdb.protocol.operation.notation.Map thresholds) { - Set channelSet2g = new HashSet<>(); - channelSet2g.add(1); - channelSet2g.add(6); - channelSet2g.add(11); - com.vmware.ovsdb.protocol.operation.notation.Set channels2g = com.vmware.ovsdb.protocol.operation.notation.Set - .of(channelSet2g); + Set channelSet2g = new HashSet<>(); + channelSet2g.add(1); + channelSet2g.add(6); + channelSet2g.add(11); + com.vmware.ovsdb.protocol.operation.notation.Set channels2g = com.vmware.ovsdb.protocol.operation.notation.Set + .of(channelSet2g); - Set channelSet5gl = new HashSet<>(); - channelSet5gl.add(36); - channelSet5gl.add(44); - channelSet5gl.add(52); - com.vmware.ovsdb.protocol.operation.notation.Set channels5gl = com.vmware.ovsdb.protocol.operation.notation.Set - .of(channelSet5gl); + Set channelSet5gl = new HashSet<>(); + channelSet5gl.add(36); + channelSet5gl.add(44); + channelSet5gl.add(52); + com.vmware.ovsdb.protocol.operation.notation.Set channels5gl = com.vmware.ovsdb.protocol.operation.notation.Set + .of(channelSet5gl); - Set channelSet5gu = new HashSet<>(); - channelSet5gu.add(100); - channelSet5gu.add(108); - channelSet5gu.add(116); - com.vmware.ovsdb.protocol.operation.notation.Set channels5gu = com.vmware.ovsdb.protocol.operation.notation.Set - .of(channelSet5gu); + Set channelSet5gu = new HashSet<>(); + channelSet5gu.add(100); + channelSet5gu.add(108); + channelSet5gu.add(116); + com.vmware.ovsdb.protocol.operation.notation.Set channels5gu = com.vmware.ovsdb.protocol.operation.notation.Set + .of(channelSet5gu); - Map updateColumns; - Row row; + Map updateColumns; + Row row; - if (!provisionedWifiStatsConfigs.containsKey("2.4G_survey_on-chan")) { - // - updateColumns = new HashMap<>(); - updateColumns.put("radio_type", new Atom<>("2.4G")); - updateColumns.put("reporting_count", new Atom<>(0)); - updateColumns.put("reporting_interval", new Atom<>(60)); - updateColumns.put("sampling_interval", new Atom<>(10)); - updateColumns.put("stats_type", new Atom<>("survey")); - updateColumns.put("survey_interval_ms", new Atom<>(0)); - updateColumns.put("survey_type", new Atom<>("on-chan")); - row = new Row(updateColumns); - operations.add(new Insert(wifiStatsConfigDbTable, row)); - // - } + if (!provisionedWifiStatsConfigs.containsKey("2.4G_survey_on-chan")) { + // + updateColumns = new HashMap<>(); + updateColumns.put("radio_type", new Atom<>("2.4G")); + updateColumns.put("reporting_count", new Atom<>(0)); + updateColumns.put("reporting_interval", new Atom<>(60)); + updateColumns.put("sampling_interval", new Atom<>(10)); + updateColumns.put("stats_type", new Atom<>("survey")); + updateColumns.put("survey_interval_ms", new Atom<>(0)); + updateColumns.put("survey_type", new Atom<>("on-chan")); + row = new Row(updateColumns); + operations.add(new Insert(wifiStatsConfigDbTable, row)); + // + } - if (!provisionedWifiStatsConfigs.containsKey("5GL_survey_on-chan")) { - // - updateColumns = new HashMap<>(); - updateColumns.put("radio_type", new Atom<>("5GL")); - updateColumns.put("reporting_count", new Atom<>(0)); - updateColumns.put("reporting_interval", new Atom<>(60)); - updateColumns.put("sampling_interval", new Atom<>(10)); - updateColumns.put("stats_type", new Atom<>("survey")); - updateColumns.put("survey_interval_ms", new Atom<>(0)); - updateColumns.put("survey_type", new Atom<>("on-chan")); - row = new Row(updateColumns); - operations.add(new Insert(wifiStatsConfigDbTable, row)); - // - } + if (!provisionedWifiStatsConfigs.containsKey("5GL_survey_on-chan")) { + // + updateColumns = new HashMap<>(); + updateColumns.put("radio_type", new Atom<>("5GL")); + updateColumns.put("reporting_count", new Atom<>(0)); + updateColumns.put("reporting_interval", new Atom<>(60)); + updateColumns.put("sampling_interval", new Atom<>(10)); + updateColumns.put("stats_type", new Atom<>("survey")); + updateColumns.put("survey_interval_ms", new Atom<>(0)); + updateColumns.put("survey_type", new Atom<>("on-chan")); + row = new Row(updateColumns); + operations.add(new Insert(wifiStatsConfigDbTable, row)); + // + } - if (!provisionedWifiStatsConfigs.containsKey("5GU_survey_on-chan")) { - updateColumns = new HashMap<>(); - updateColumns.put("radio_type", new Atom<>("5GU")); - updateColumns.put("reporting_count", new Atom<>(0)); - updateColumns.put("reporting_interval", new Atom<>(60)); - updateColumns.put("sampling_interval", new Atom<>(10)); - updateColumns.put("stats_type", new Atom<>("survey")); - updateColumns.put("survey_interval_ms", new Atom<>(0)); - updateColumns.put("survey_type", new Atom<>("on-chan")); - row = new Row(updateColumns); - operations.add(new Insert(wifiStatsConfigDbTable, row)); - } + if (!provisionedWifiStatsConfigs.containsKey("5GU_survey_on-chan")) { + updateColumns = new HashMap<>(); + updateColumns.put("radio_type", new Atom<>("5GU")); + updateColumns.put("reporting_count", new Atom<>(0)); + updateColumns.put("reporting_interval", new Atom<>(60)); + updateColumns.put("sampling_interval", new Atom<>(10)); + updateColumns.put("stats_type", new Atom<>("survey")); + updateColumns.put("survey_interval_ms", new Atom<>(0)); + updateColumns.put("survey_type", new Atom<>("on-chan")); + row = new Row(updateColumns); + operations.add(new Insert(wifiStatsConfigDbTable, row)); + } - if (!provisionedWifiStatsConfigs.containsKey("2.4G_survey_off-chan")) { - // - updateColumns = new HashMap<>(); - updateColumns.put("channel_list", channels2g); - updateColumns.put("radio_type", new Atom<>("2.4G")); - updateColumns.put("reporting_interval", new Atom<>(0)); - updateColumns.put("sampling_interval", new Atom<>(0)); - updateColumns.put("stats_type", new Atom<>("survey")); - updateColumns.put("survey_interval_ms", new Atom<>(10)); - updateColumns.put("survey_type", new Atom<>("off-chan")); - updateColumns.put("threshold", thresholds); - row = new Row(updateColumns); - operations.add(new Insert(wifiStatsConfigDbTable, row)); - // - } + if (!provisionedWifiStatsConfigs.containsKey("2.4G_survey_off-chan")) { + // + updateColumns = new HashMap<>(); + updateColumns.put("channel_list", channels2g); + updateColumns.put("radio_type", new Atom<>("2.4G")); + updateColumns.put("reporting_interval", new Atom<>(0)); + updateColumns.put("sampling_interval", new Atom<>(0)); + updateColumns.put("stats_type", new Atom<>("survey")); + updateColumns.put("survey_interval_ms", new Atom<>(10)); + updateColumns.put("survey_type", new Atom<>("off-chan")); + updateColumns.put("threshold", thresholds); + row = new Row(updateColumns); + operations.add(new Insert(wifiStatsConfigDbTable, row)); + // + } - if (!provisionedWifiStatsConfigs.containsKey("5GL_survey_off-chan")) { - // - updateColumns = new HashMap<>(); - updateColumns.put("channel_list", channels5gl); - updateColumns.put("radio_type", new Atom<>("5GL")); - updateColumns.put("reporting_interval", new Atom<>(0)); - updateColumns.put("sampling_interval", new Atom<>(0)); - updateColumns.put("stats_type", new Atom<>("survey")); - updateColumns.put("survey_interval_ms", new Atom<>(10)); - updateColumns.put("survey_type", new Atom<>("off-chan")); - updateColumns.put("threshold", thresholds); - row = new Row(updateColumns); - operations.add(new Insert(wifiStatsConfigDbTable, row)); - // - } + if (!provisionedWifiStatsConfigs.containsKey("5GL_survey_off-chan")) { + // + updateColumns = new HashMap<>(); + updateColumns.put("channel_list", channels5gl); + updateColumns.put("radio_type", new Atom<>("5GL")); + updateColumns.put("reporting_interval", new Atom<>(0)); + updateColumns.put("sampling_interval", new Atom<>(0)); + updateColumns.put("stats_type", new Atom<>("survey")); + updateColumns.put("survey_interval_ms", new Atom<>(10)); + updateColumns.put("survey_type", new Atom<>("off-chan")); + updateColumns.put("threshold", thresholds); + row = new Row(updateColumns); + operations.add(new Insert(wifiStatsConfigDbTable, row)); + // + } - if (!provisionedWifiStatsConfigs.containsKey("5GU_survey_off-chan")) { - // - updateColumns = new HashMap<>(); - updateColumns.put("channel_list", channels5gu); - updateColumns.put("radio_type", new Atom<>("5GU")); - updateColumns.put("reporting_interval", new Atom<>(0)); - updateColumns.put("sampling_interval", new Atom<>(0)); - updateColumns.put("stats_type", new Atom<>("survey")); - updateColumns.put("survey_interval_ms", new Atom<>(10)); - updateColumns.put("survey_type", new Atom<>("off-chan")); - updateColumns.put("threshold", thresholds); - row = new Row(updateColumns); - operations.add(new Insert(wifiStatsConfigDbTable, row)); - // - } + if (!provisionedWifiStatsConfigs.containsKey("5GU_survey_off-chan")) { + // + updateColumns = new HashMap<>(); + updateColumns.put("channel_list", channels5gu); + updateColumns.put("radio_type", new Atom<>("5GU")); + updateColumns.put("reporting_interval", new Atom<>(0)); + updateColumns.put("sampling_interval", new Atom<>(0)); + updateColumns.put("stats_type", new Atom<>("survey")); + updateColumns.put("survey_interval_ms", new Atom<>(10)); + updateColumns.put("survey_type", new Atom<>("off-chan")); + updateColumns.put("threshold", thresholds); + row = new Row(updateColumns); + operations.add(new Insert(wifiStatsConfigDbTable, row)); + // + } - } + } // private void provisionWifiStatsConfigDevice(Map provisionedWifiStatsConfigs, // List operations, Map updateColumns) { @@ -2609,74 +2569,73 @@ public class OvsdbDao { // // } - private void provisionWifiStatsConfigClient(Map provisionedWifiStatsConfigs, - List operations) { - Map updateColumns; - Row row; - if (!provisionedWifiStatsConfigs.containsKey("2.4G_client")) { - updateColumns = new HashMap<>(); - updateColumns.put("radio_type", new Atom<>("2.4G")); - updateColumns.put("reporting_count", new Atom<>(0)); - updateColumns.put("reporting_interval", new Atom<>(60)); - updateColumns.put("sampling_interval", new Atom<>(10)); - updateColumns.put("stats_type", new Atom<>("client")); - row = new Row(updateColumns); - operations.add(new Insert(wifiStatsConfigDbTable, row)); - } + private void provisionWifiStatsConfigClient(Map provisionedWifiStatsConfigs, + List operations) { + Map updateColumns; + Row row; + if (!provisionedWifiStatsConfigs.containsKey("2.4G_client")) { + updateColumns = new HashMap<>(); + updateColumns.put("radio_type", new Atom<>("2.4G")); + updateColumns.put("reporting_count", new Atom<>(0)); + updateColumns.put("reporting_interval", new Atom<>(60)); + updateColumns.put("sampling_interval", new Atom<>(10)); + updateColumns.put("stats_type", new Atom<>("client")); + row = new Row(updateColumns); + operations.add(new Insert(wifiStatsConfigDbTable, row)); + } - if (!provisionedWifiStatsConfigs.containsKey("5GL_client")) { + if (!provisionedWifiStatsConfigs.containsKey("5GL_client")) { - updateColumns = new HashMap<>(); - updateColumns.put("radio_type", new Atom<>("5GL")); - updateColumns.put("reporting_count", new Atom<>(0)); - updateColumns.put("reporting_interval", new Atom<>(60)); - updateColumns.put("sampling_interval", new Atom<>(10)); - updateColumns.put("stats_type", new Atom<>("client")); - row = new Row(updateColumns); - operations.add(new Insert(wifiStatsConfigDbTable, row)); + updateColumns = new HashMap<>(); + updateColumns.put("radio_type", new Atom<>("5GL")); + updateColumns.put("reporting_count", new Atom<>(0)); + updateColumns.put("reporting_interval", new Atom<>(60)); + updateColumns.put("sampling_interval", new Atom<>(10)); + updateColumns.put("stats_type", new Atom<>("client")); + row = new Row(updateColumns); + operations.add(new Insert(wifiStatsConfigDbTable, row)); - } + } - if (!provisionedWifiStatsConfigs.containsKey("5GU_client")) { + if (!provisionedWifiStatsConfigs.containsKey("5GU_client")) { - updateColumns = new HashMap<>(); - updateColumns.put("radio_type", new Atom<>("5GU")); - updateColumns.put("reporting_count", new Atom<>(0)); - updateColumns.put("reporting_interval", new Atom<>(60)); - updateColumns.put("sampling_interval", new Atom<>(10)); - updateColumns.put("stats_type", new Atom<>("client")); - row = new Row(updateColumns); - operations.add(new Insert(wifiStatsConfigDbTable, row)); - } - } + updateColumns = new HashMap<>(); + updateColumns.put("radio_type", new Atom<>("5GU")); + updateColumns.put("reporting_count", new Atom<>(0)); + updateColumns.put("reporting_interval", new Atom<>(60)); + updateColumns.put("sampling_interval", new Atom<>(10)); + updateColumns.put("stats_type", new Atom<>("client")); + row = new Row(updateColumns); + operations.add(new Insert(wifiStatsConfigDbTable, row)); + } + } - public String changeRedirectorAddress(OvsdbClient ovsdbClient, String apId, String newRedirectorAddress) { - try { - List operations = new ArrayList<>(); - Map updateColumns = new HashMap<>(); + public String changeRedirectorAddress(OvsdbClient ovsdbClient, String apId, String newRedirectorAddress) { + try { + List operations = new ArrayList<>(); + Map updateColumns = new HashMap<>(); - updateColumns.put("redirector_addr", new Atom<>(newRedirectorAddress)); + updateColumns.put("redirector_addr", new Atom<>(newRedirectorAddress)); - Row row = new Row(updateColumns); - operations.add(new Update(awlanNodeDbTable, row)); + Row row = new Row(updateColumns); + operations.add(new Update(awlanNodeDbTable, row)); - CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); - OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); - if (LOG.isDebugEnabled()) { - LOG.debug("Updated {} redirector_addr = {}", awlanNodeDbTable, newRedirectorAddress); + if (LOG.isDebugEnabled()) { + LOG.debug("Updated {} redirector_addr = {}", awlanNodeDbTable, newRedirectorAddress); - for (OperationResult res : result) { - LOG.debug("Op Result {}", res); - } - } + for (OperationResult res : result) { + LOG.debug("Op Result {}", res); + } + } - } - catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { - throw new RuntimeException(e); - } + } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { + throw new RuntimeException(e); + } - return newRedirectorAddress; - } + return newRedirectorAddress; + } }