mirror of
https://github.com/Telecominfraproject/wlan-cloud-opensync-controller.git
synced 2025-11-22 04:45:08 +00:00
Wifi_Radio_State table updates handling. Remove temp objects, begin refactor for MQTT messages
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -6,6 +6,7 @@ package com.telecominfraproject.wlan.opensync.external.integration.models;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.telecominfraproject.wlan.core.model.equipment.RadioType;
|
||||
import com.telecominfraproject.wlan.core.model.json.BaseJsonModel;
|
||||
import com.vmware.ovsdb.protocol.operation.notation.Uuid;
|
||||
|
||||
@@ -41,7 +42,7 @@ public class OpensyncAPRadioState extends BaseJsonModel {
|
||||
public Map<String, String> channels;
|
||||
public int thermalUpgradeTemp;
|
||||
public Map<String, String> hwParams;
|
||||
public String freqBand;
|
||||
public RadioType freqBand;
|
||||
public int thermalIntegration;
|
||||
public String channelMode;
|
||||
public Uuid _uuid;
|
||||
@@ -239,11 +240,11 @@ public class OpensyncAPRadioState extends BaseJsonModel {
|
||||
this.hwParams = hwParams;
|
||||
}
|
||||
|
||||
public String getFreqBand() {
|
||||
public RadioType getFreqBand() {
|
||||
return freqBand;
|
||||
}
|
||||
|
||||
public void setFreqBand(String freqBand) {
|
||||
public void setFreqBand(RadioType freqBand) {
|
||||
this.freqBand = freqBand;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,5 +20,5 @@
|
||||
<listAttribute key="org.eclipse.jdt.launching.MODULEPATH"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="opensync-gateway-cloud-process"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="--add-opens java.base/java.lang=ALL-UNNAMED -Dssl.props=file://${project_loc:opensync-gateway-cloud-process}/src/main/resources/app/certs/ssl.properties -Dtip.wlan.httpClientConfig=file://${project_loc:opensync-gateway-cloud-process}/src/main/resources/app/certs/httpClientConfig.json -Djavax.net.ssl.keyStore=${connectus_certs}/client_keystore.jks -Djavax.net.ssl.keyStorePassword=mypassword -Djavax.net.ssl.trustStore=${connectus_certs}/truststore.jks -Djavax.net.ssl.trustStorePassword=mypassword -Dconnectus.ovsdb.managerAddr=${local_server_address} -Dconnectus.ovsdb.listenPort=6640 -Dconnectus.ovsdb.redirector.listenPort=6643 -Dconnectus.ovsdb.timeoutSec=30 -Dconnectus.ovsdb.trustStore=${connectus_certs}/truststore.jks -Dconnectus.ovsdb.keyStore=${connectus_certs}/server.pkcs12 -Dconnectus.mqttBroker.address=${local_server_address} -Dconnectus.mqttBroker.listenPort=1883 -Dtip.wlan.introspectTokenApi.host=localhost:9096 -Dtip.wlan.introspectTokenApi.clientToken=token_placeholder -Dtip.wlan.serviceUser=user -Dtip.wlan.servicePassword=password -Dconnectus.ovsdb.autoProvisionedCustomerId=2 -Dconnectus.ovsdb.autoProvisionedSsid=Connectus-cloud -Dconnectus.ovsdb.wifi-iface.default_radio1=home-ap-24 -Dconnectus.ovsdb.wifi-iface.default_radio2=home-ap-l50 -Dconnectus.ovsdb.wifi-iface.default_radio0=home-ap-u50	 -Dconnectus.ovsdb.wifi-device.radio0=wifi2 -Dconnectus.ovsdb.wifi-device.radio1=wifi0 -Dconnectus.ovsdb.wifi-device.radio2=wifi1 -Dspring.main.show-banner=false -Dserver.port=9096 -Dtip.wlan.secondaryPort=9097 -Dtip.wlan.csrf-enabled=false -Dspring.profiles.include=opensync_cloud_config,mqtt_receiver,ovsdb_redirector,ovsdb_manager"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="--add-opens java.base/java.lang=ALL-UNNAMED -Dssl.props=file://${project_loc:opensync-gateway-cloud-process}/src/main/resources/app/certs/ssl.properties -Dtip.wlan.httpClientConfig=file://${project_loc:opensync-gateway-cloud-process}/src/main/resources/app/certs/httpClientConfig.json -Djavax.net.ssl.keyStore=${connectus_certs}/client_keystore.jks -Djavax.net.ssl.keyStorePassword=mypassword -Djavax.net.ssl.trustStore=${connectus_certs}/truststore.jks -Djavax.net.ssl.trustStorePassword=mypassword -Dconnectus.ovsdb.managerAddr=${local_server_address} -Dconnectus.ovsdb.listenPort=6640 -Dconnectus.ovsdb.redirector.listenPort=6643 -Dconnectus.ovsdb.timeoutSec=30 -Dconnectus.ovsdb.trustStore=${connectus_certs}/truststore.jks -Dconnectus.ovsdb.keyStore=${connectus_certs}/server.pkcs12 -Dconnectus.mqttBroker.address=${local_server_address} -Dconnectus.mqttBroker.listenPort=1883 -Dtip.wlan.introspectTokenApi.host=${local_server_address}:9096 -Dtip.wlan.introspectTokenApi.clientToken=token_placeholder -Dtip.wlan.serviceUser=user -Dtip.wlan.servicePassword=password -Dconnectus.ovsdb.autoProvisionedCustomerId=2 -Dconnectus.ovsdb.autoProvisionedSsid=Connectus-cloud -Dspring.main.show-banner=false -Dserver.port=9096 -Dtip.wlan.secondaryPort=7071 -Dtip.wlan.csrf-enabled=false -Dspring.profiles.include=opensync_cloud_config,mqtt_receiver,ovsdb_redirector,ovsdb_manager"/>
|
||||
</launchConfiguration>
|
||||
|
||||
@@ -45,370 +45,378 @@ import io.netty.handler.ssl.SslContext;
|
||||
@Component
|
||||
public class ConnectusOvsdbClient implements ConnectusOvsdbClientInterface {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ConnectusOvsdbClient.class);
|
||||
|
||||
@org.springframework.beans.factory.annotation.Value("${connectus.ovsdb.listenPort:6640}")
|
||||
private int ovsdbListenPort;
|
||||
|
||||
@org.springframework.beans.factory.annotation.Value("${connectus.manager.collectionIntervalSec.deviceStats:10}")
|
||||
private long collectionIntervalSecDeviceStats;
|
||||
|
||||
@Autowired
|
||||
private SslContext sslContext;
|
||||
|
||||
@Autowired
|
||||
private OvsdbPassiveConnectionListener listener;
|
||||
|
||||
@Autowired
|
||||
private OvsdbDao ovsdbDao;
|
||||
|
||||
@Autowired
|
||||
private OpensyncExternalIntegrationInterface extIntegrationInterface;
|
||||
|
||||
@Autowired
|
||||
private OvsdbSessionMapInterface ovsdbSessionMapInterface;
|
||||
|
||||
@PostConstruct
|
||||
private void postCreate() {
|
||||
listenForConnections();
|
||||
}
|
||||
|
||||
public void listenForConnections() {
|
||||
|
||||
ConnectionCallback connectionCallback = new ConnectionCallback() {
|
||||
public void connected(OvsdbClient ovsdbClient) {
|
||||
String remoteHost = ovsdbClient.getConnectionInfo().getRemoteAddress().getHostAddress();
|
||||
int localPort = ovsdbClient.getConnectionInfo().getLocalPort();
|
||||
String subjectDn = null;
|
||||
try {
|
||||
subjectDn = ((X509Certificate) ovsdbClient.getConnectionInfo().getRemoteCertificate())
|
||||
.getSubjectDN().getName();
|
||||
|
||||
String clientCn = SslUtil.extractCN(subjectDn);
|
||||
LOG.info("ovsdbClient connecting from {} on port {} clientCn {}", remoteHost, localPort, clientCn);
|
||||
|
||||
ConnectNodeInfo connectNodeInfo = ovsdbDao.getConnectNodeInfo(ovsdbClient);
|
||||
|
||||
// successfully connected - register it in our
|
||||
// connectedClients table
|
||||
// In Plume's environment clientCn is not unique that's why
|
||||
// we are augmenting it
|
||||
// with the serialNumber and using it as a key (equivalent
|
||||
// of KDC unique qrCode)
|
||||
String key = clientCn + "_" + connectNodeInfo.serialNumber;
|
||||
ConnectusOvsdbClient.this.ovsdbSessionMapInterface.newSession(key, ovsdbClient);
|
||||
extIntegrationInterface.apConnected(key, connectNodeInfo);
|
||||
monitorOvsdbStateTables(ovsdbClient, key);
|
||||
|
||||
// push configuration to AP
|
||||
connectNodeInfo = processConnectRequest(ovsdbClient, clientCn, connectNodeInfo);
|
||||
|
||||
LOG.info("ovsdbClient connected from {} on port {} key {} ", remoteHost, localPort, key);
|
||||
LOG.info("ovsdbClient connectedClients = {}",
|
||||
ConnectusOvsdbClient.this.ovsdbSessionMapInterface.getNumSessions());
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
LOG.error("ovsdbClient error", e);
|
||||
// something is wrong with the SSL
|
||||
ovsdbClient.shutdown();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void disconnected(OvsdbClient ovsdbClient) {
|
||||
String remoteHost = ovsdbClient.getConnectionInfo().getRemoteAddress().getHostAddress();
|
||||
int localPort = ovsdbClient.getConnectionInfo().getLocalPort();
|
||||
String subjectDn = null;
|
||||
try {
|
||||
subjectDn = ((X509Certificate) ovsdbClient.getConnectionInfo().getRemoteCertificate())
|
||||
.getSubjectDN().getName();
|
||||
} catch (Exception e) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
String clientCn = SslUtil.extractCN(subjectDn);
|
||||
|
||||
// disconnected - deregister ovsdbClient from our
|
||||
// connectedClients table
|
||||
// unfortunately we only know clientCn at this point, but in
|
||||
// Plume's environment
|
||||
// they are not unique
|
||||
// so we are doing a reverse lookup here, and then if we find
|
||||
// the key we will
|
||||
// remove the entry from the connectedClients.
|
||||
String key = ConnectusOvsdbClient.this.ovsdbSessionMapInterface.lookupClientId(ovsdbClient);
|
||||
|
||||
if (key != null) {
|
||||
|
||||
// turn off monitor
|
||||
try {
|
||||
ovsdbClient.cancelMonitor(OvsdbDao.wifiRadioStateDbTable + "_" + key);
|
||||
ovsdbClient.cancelMonitor(OvsdbDao.wifiVifStateDbTable + "_" + key);
|
||||
ovsdbClient.cancelMonitor(OvsdbDao.wifiInetStateDbTable + "_" + key);
|
||||
ovsdbClient.cancelMonitor(OvsdbDao.wifiAssociatedClientsDbTable + "_" + key);
|
||||
ovsdbClient.cancelMonitor(OvsdbDao.awlanNodeDbTable + "_" + key);
|
||||
|
||||
} catch (OvsdbClientException e) {
|
||||
LOG.warn("Could not cancel Monitor {}", e.getMessage());
|
||||
}
|
||||
|
||||
extIntegrationInterface.apDisconnected(key);
|
||||
ConnectusOvsdbClient.this.ovsdbSessionMapInterface.removeSession(key);
|
||||
}
|
||||
|
||||
ovsdbClient.shutdown();
|
||||
|
||||
LOG.info("ovsdbClient disconnected from {} on port {} clientCn {} key {} ", remoteHost, localPort,
|
||||
clientCn, key);
|
||||
LOG.info("ovsdbClient connectedClients = {}",
|
||||
ConnectusOvsdbClient.this.ovsdbSessionMapInterface.getNumSessions());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
listener.startListeningWithSsl(ovsdbListenPort, sslContext, connectionCallback).join();
|
||||
|
||||
LOG.debug("manager waiting for connection on port {}...", ovsdbListenPort);
|
||||
}
|
||||
|
||||
private ConnectNodeInfo processConnectRequest(OvsdbClient ovsdbClient, String clientCn,
|
||||
ConnectNodeInfo connectNodeInfo) {
|
||||
|
||||
LOG.debug("Starting Client connect");
|
||||
connectNodeInfo = ovsdbDao.updateConnectNodeInfoOnConnect(ovsdbClient, clientCn, connectNodeInfo);
|
||||
|
||||
String apId = clientCn + "_" + connectNodeInfo.serialNumber;
|
||||
OpensyncAPConfig opensyncAPConfig = extIntegrationInterface.getApConfig(apId);
|
||||
|
||||
ovsdbDao.configureStats(ovsdbClient);
|
||||
|
||||
// Check if device stats is configured in Wifi_Stats_Config table,
|
||||
// provision it
|
||||
// if needed
|
||||
if (ovsdbDao.getDeviceStatsReportingInterval(ovsdbClient) != collectionIntervalSecDeviceStats) {
|
||||
ovsdbDao.updateDeviceStatsReportingInterval(ovsdbClient, collectionIntervalSecDeviceStats);
|
||||
}
|
||||
|
||||
try {
|
||||
ovsdbDao.provisionBridgePortInterface(ovsdbClient);
|
||||
} catch (Exception e) {
|
||||
// TODO: for some AP configurations this 'may' not be necessary.
|
||||
LOG.warn("Could not provision Bridge->Port->Interface mapping.", e);
|
||||
}
|
||||
|
||||
ovsdbDao.removeAllSsids(ovsdbClient);
|
||||
|
||||
if (opensyncAPConfig != null) {
|
||||
ovsdbDao.configureWifiRadios(ovsdbClient, opensyncAPConfig);
|
||||
ovsdbDao.configureSsids(ovsdbClient, opensyncAPConfig);
|
||||
}
|
||||
|
||||
// ovsdbDao.configureWifiInet(ovsdbClient);
|
||||
|
||||
LOG.debug("Client connect Done");
|
||||
return connectNodeInfo;
|
||||
}
|
||||
|
||||
public Set<String> getConnectedClientIds() {
|
||||
return ovsdbSessionMapInterface.getConnectedClientIds();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param apId
|
||||
* @param newRedirectorAddress
|
||||
* @return updated value of the redirector
|
||||
*/
|
||||
public String changeRedirectorAddress(String apId, String newRedirectorAddress) {
|
||||
OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId);
|
||||
if (ovsdbSession == null) {
|
||||
throw new IllegalStateException("AP with id " + apId + " is not connected");
|
||||
}
|
||||
|
||||
String ret = ovsdbDao.changeRedirectorAddress(ovsdbSession.getOvsdbClient(), apId, newRedirectorAddress);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processConfigChanged(String apId) {
|
||||
LOG.debug("Starting processConfigChanged for {}", apId);
|
||||
|
||||
OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId);
|
||||
if (ovsdbSession == null) {
|
||||
throw new IllegalStateException("AP with id " + apId + " is not connected");
|
||||
}
|
||||
|
||||
OvsdbClient ovsdbClient = ovsdbSession.getOvsdbClient();
|
||||
OpensyncAPConfig opensyncAPConfig = extIntegrationInterface.getApConfig(apId);
|
||||
|
||||
if (opensyncAPConfig != null) {
|
||||
ovsdbDao.removeAllSsids(ovsdbClient);
|
||||
ovsdbDao.configureWifiRadios(ovsdbClient, opensyncAPConfig);
|
||||
ovsdbDao.configureSsids(ovsdbClient, opensyncAPConfig);
|
||||
}
|
||||
|
||||
LOG.debug("Finished processConfigChanged for {}", apId);
|
||||
}
|
||||
|
||||
private void monitorOvsdbStateTables(OvsdbClient ovsdbClient, String key) throws OvsdbClientException {
|
||||
CompletableFuture<TableUpdates> rsCf = ovsdbClient
|
||||
.monitor(OvsdbDao.ovsdbName, OvsdbDao.wifiRadioStateDbTable + "_" + key,
|
||||
new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiRadioStateDbTable,
|
||||
new MonitorRequest(new MonitorSelect(true, true, true, true)))),
|
||||
new MonitorCallback() {
|
||||
|
||||
@Override
|
||||
public void update(TableUpdates tableUpdates) {
|
||||
extIntegrationInterface.wifiRadioStatusDbTableUpdate(
|
||||
ovsdbDao.getOpensyncAPRadioState(tableUpdates, key, ovsdbClient), key);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
extIntegrationInterface
|
||||
.wifiRadioStatusDbTableUpdate(ovsdbDao.getOpensyncAPRadioState(rsCf.join(), key, ovsdbClient), key);
|
||||
|
||||
CompletableFuture<TableUpdates> isCf = ovsdbClient
|
||||
.monitor(OvsdbDao.ovsdbName, OvsdbDao.wifiInetStateDbTable + "_" + key,
|
||||
new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiInetStateDbTable,
|
||||
new MonitorRequest(new MonitorSelect(true, true, true, true)))),
|
||||
new MonitorCallback() {
|
||||
|
||||
@Override
|
||||
public void update(TableUpdates tableUpdates) {
|
||||
|
||||
extIntegrationInterface.wifiInetStateDbTableUpdate(
|
||||
ovsdbDao.getOpensyncAPInetState(tableUpdates, key, ovsdbClient), key);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
extIntegrationInterface
|
||||
.wifiInetStateDbTableUpdate(ovsdbDao.getOpensyncAPInetState(isCf.join(), key, ovsdbClient), key);
|
||||
|
||||
CompletableFuture<TableUpdates> vsCf = ovsdbClient.monitor(OvsdbDao.ovsdbName,
|
||||
OvsdbDao.wifiVifStateDbTable + "_" + key,
|
||||
new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiVifStateDbTable,
|
||||
new MonitorRequest(new MonitorSelect(true, true, true, true)))),
|
||||
new MonitorCallback() {
|
||||
@Override
|
||||
public void update(TableUpdates tableUpdates) {
|
||||
// extIntegrationInterface.wifiVIFStateDbTableUpdate(
|
||||
// ovsdbDao.getOpensyncAPVIFState(tableUpdates,
|
||||
// key, ovsdbClient), key);
|
||||
List<OpensyncAPVIFState> vifsToDelete = new ArrayList<OpensyncAPVIFState>();
|
||||
for (Entry<String, TableUpdate> tableUpdate : tableUpdates.getTableUpdates().entrySet()) {
|
||||
|
||||
for (Entry<UUID, RowUpdate> rowUpdate : tableUpdate.getValue().getRowUpdates().entrySet()) {
|
||||
if (rowUpdate.getValue().getOld() != null && rowUpdate.getValue().getNew() == null) {
|
||||
Row row = rowUpdate.getValue().getOld();
|
||||
String ifName = null;
|
||||
String ssid = null;
|
||||
if (row.getColumns().get("ssid") != null && row.getColumns().get("ssid").getClass()
|
||||
.equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) {
|
||||
ssid = row.getStringColumn("ssid");
|
||||
}
|
||||
if (row.getColumns().get("if_name") != null
|
||||
&& row.getColumns().get("if_name").getClass()
|
||||
.equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) {
|
||||
ifName = row.getStringColumn("if_name");
|
||||
}
|
||||
if (ifName != null && ssid != null) {
|
||||
OpensyncAPVIFState toBeDeleted = new OpensyncAPVIFState();
|
||||
toBeDeleted.setSsid(ssid);
|
||||
toBeDeleted.setIfName(ifName);
|
||||
vifsToDelete.add(toBeDeleted);
|
||||
}
|
||||
tableUpdate.getValue().getRowUpdates().remove(rowUpdate.getKey());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (tableUpdate.getValue().getRowUpdates().values().isEmpty()) {
|
||||
tableUpdates.getTableUpdates().remove(tableUpdate.getKey());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!vifsToDelete.isEmpty()) {
|
||||
extIntegrationInterface.wifiVIFStateDbTableDelete(vifsToDelete, key);
|
||||
}
|
||||
if (tableUpdates.getTableUpdates().entrySet().isEmpty())
|
||||
extIntegrationInterface.wifiVIFStateDbTableUpdate(
|
||||
ovsdbDao.getOpensyncAPVIFState(tableUpdates, key, ovsdbClient), key);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
extIntegrationInterface.wifiVIFStateDbTableUpdate(ovsdbDao.getOpensyncAPVIFState(vsCf.join(), key, ovsdbClient),
|
||||
key);
|
||||
|
||||
CompletableFuture<TableUpdates> acCf = ovsdbClient.monitor(OvsdbDao.ovsdbName,
|
||||
OvsdbDao.wifiAssociatedClientsDbTable + "_" + key,
|
||||
new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiAssociatedClientsDbTable,
|
||||
new MonitorRequest(new MonitorSelect(true, true, true, true)))),
|
||||
new MonitorCallback() {
|
||||
|
||||
@Override
|
||||
public void update(TableUpdates tableUpdates) {
|
||||
|
||||
boolean insertOrModify = false;
|
||||
for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) {
|
||||
|
||||
for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) {
|
||||
if (rowUpdate.getOld() != null && rowUpdate.getNew() == null) {
|
||||
insertOrModify = false;
|
||||
Row row = rowUpdate.getOld();
|
||||
String deletedClientMac = row.getStringColumn("mac");
|
||||
extIntegrationInterface.wifiAssociatedClientsDbTableDelete(deletedClientMac, key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (insertOrModify) {
|
||||
extIntegrationInterface.wifiAssociatedClientsDbTableUpdate(
|
||||
ovsdbDao.getOpensyncWifiAssociatedClients(tableUpdates, key, ovsdbClient), key);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
extIntegrationInterface.wifiAssociatedClientsDbTableUpdate(
|
||||
ovsdbDao.getOpensyncWifiAssociatedClients(acCf.join(), key, ovsdbClient), key);
|
||||
|
||||
CompletableFuture<TableUpdates> awCf = ovsdbClient
|
||||
.monitor(OvsdbDao.ovsdbName, OvsdbDao.awlanNodeDbTable + "_" + key,
|
||||
new MonitorRequests(ImmutableMap.of(OvsdbDao.awlanNodeDbTable,
|
||||
new MonitorRequest(new MonitorSelect(true, true, true, true)))),
|
||||
new MonitorCallback() {
|
||||
|
||||
@Override
|
||||
public void update(TableUpdates tableUpdates) {
|
||||
extIntegrationInterface.awlanNodeDbTableUpdate(
|
||||
ovsdbDao.getOpensyncAWLANNode(tableUpdates, key, ovsdbClient), key);
|
||||
}
|
||||
|
||||
});
|
||||
extIntegrationInterface.awlanNodeDbTableUpdate(ovsdbDao.getOpensyncAWLANNode(awCf.join(), key, ovsdbClient),
|
||||
key);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String closeSession(String apId) {
|
||||
OvsdbSession session = ovsdbSessionMapInterface.getSession(apId);
|
||||
try {
|
||||
session.getOvsdbClient().shutdown();
|
||||
} catch (Exception e) {
|
||||
LOG.error("Failed to close session to " + apId + " " + e.getLocalizedMessage());
|
||||
return "Failed to close session to " + apId + " " + e.getLocalizedMessage();
|
||||
|
||||
}
|
||||
LOG.debug("Closed session to " + apId);
|
||||
return "Closed session to " + apId;
|
||||
}
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ConnectusOvsdbClient.class);
|
||||
|
||||
@org.springframework.beans.factory.annotation.Value("${connectus.ovsdb.listenPort:6640}")
|
||||
private int ovsdbListenPort;
|
||||
|
||||
@org.springframework.beans.factory.annotation.Value("${connectus.manager.collectionIntervalSec.deviceStats:10}")
|
||||
private long collectionIntervalSecDeviceStats;
|
||||
|
||||
@Autowired
|
||||
private SslContext sslContext;
|
||||
|
||||
@Autowired
|
||||
private OvsdbPassiveConnectionListener listener;
|
||||
|
||||
@Autowired
|
||||
private OvsdbDao ovsdbDao;
|
||||
|
||||
@Autowired
|
||||
private OpensyncExternalIntegrationInterface extIntegrationInterface;
|
||||
|
||||
@Autowired
|
||||
private OvsdbSessionMapInterface ovsdbSessionMapInterface;
|
||||
|
||||
@PostConstruct
|
||||
private void postCreate() {
|
||||
listenForConnections();
|
||||
}
|
||||
|
||||
public void listenForConnections() {
|
||||
|
||||
ConnectionCallback connectionCallback = new ConnectionCallback() {
|
||||
@Override
|
||||
public void connected(OvsdbClient ovsdbClient) {
|
||||
String remoteHost = ovsdbClient.getConnectionInfo().getRemoteAddress().getHostAddress();
|
||||
int localPort = ovsdbClient.getConnectionInfo().getLocalPort();
|
||||
String subjectDn = null;
|
||||
try {
|
||||
subjectDn = ((X509Certificate) ovsdbClient.getConnectionInfo().getRemoteCertificate())
|
||||
.getSubjectDN().getName();
|
||||
|
||||
String clientCn = SslUtil.extractCN(subjectDn);
|
||||
LOG.info("ovsdbClient connecting from {} on port {} clientCn {}", remoteHost, localPort, clientCn);
|
||||
|
||||
ConnectNodeInfo connectNodeInfo = ovsdbDao.getConnectNodeInfo(ovsdbClient);
|
||||
|
||||
// successfully connected - register it in our
|
||||
// connectedClients table
|
||||
// In Plume's environment clientCn is not unique that's why
|
||||
// we are augmenting it
|
||||
// with the serialNumber and using it as a key (equivalent
|
||||
// of KDC unique qrCode)
|
||||
String key = clientCn + "_" + connectNodeInfo.serialNumber;
|
||||
ConnectusOvsdbClient.this.ovsdbSessionMapInterface.newSession(key, ovsdbClient);
|
||||
extIntegrationInterface.apConnected(key, connectNodeInfo);
|
||||
|
||||
// push configuration to AP
|
||||
connectNodeInfo = processConnectRequest(ovsdbClient, clientCn, connectNodeInfo);
|
||||
monitorOvsdbStateTables(ovsdbClient, key);
|
||||
|
||||
LOG.info("ovsdbClient connected from {} on port {} key {} ", remoteHost, localPort, key);
|
||||
LOG.info("ovsdbClient connectedClients = {}",
|
||||
ConnectusOvsdbClient.this.ovsdbSessionMapInterface.getNumSessions());
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.error("ovsdbClient error", e);
|
||||
// something is wrong with the SSL
|
||||
ovsdbClient.shutdown();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnected(OvsdbClient ovsdbClient) {
|
||||
String remoteHost = ovsdbClient.getConnectionInfo().getRemoteAddress().getHostAddress();
|
||||
int localPort = ovsdbClient.getConnectionInfo().getLocalPort();
|
||||
String subjectDn = null;
|
||||
try {
|
||||
subjectDn = ((X509Certificate) ovsdbClient.getConnectionInfo().getRemoteCertificate())
|
||||
.getSubjectDN().getName();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
String clientCn = SslUtil.extractCN(subjectDn);
|
||||
|
||||
// disconnected - deregister ovsdbClient from our
|
||||
// connectedClients table
|
||||
// unfortunately we only know clientCn at this point, but in
|
||||
// Plume's environment
|
||||
// they are not unique
|
||||
// so we are doing a reverse lookup here, and then if we find
|
||||
// the key we will
|
||||
// remove the entry from the connectedClients.
|
||||
String key = ConnectusOvsdbClient.this.ovsdbSessionMapInterface.lookupClientId(ovsdbClient);
|
||||
|
||||
if (key != null) {
|
||||
|
||||
// turn off monitor
|
||||
try {
|
||||
ovsdbClient.cancelMonitor(OvsdbDao.wifiRadioStateDbTable + "_" + key);
|
||||
ovsdbClient.cancelMonitor(OvsdbDao.wifiVifStateDbTable + "_" + key);
|
||||
ovsdbClient.cancelMonitor(OvsdbDao.wifiInetStateDbTable + "_" + key);
|
||||
ovsdbClient.cancelMonitor(OvsdbDao.wifiAssociatedClientsDbTable + "_" + key);
|
||||
ovsdbClient.cancelMonitor(OvsdbDao.awlanNodeDbTable + "_" + key);
|
||||
|
||||
}
|
||||
catch (OvsdbClientException e) {
|
||||
LOG.warn("Could not cancel Monitor {}", e.getMessage());
|
||||
}
|
||||
|
||||
extIntegrationInterface.apDisconnected(key);
|
||||
ConnectusOvsdbClient.this.ovsdbSessionMapInterface.removeSession(key);
|
||||
}
|
||||
|
||||
ovsdbClient.shutdown();
|
||||
|
||||
LOG.info("ovsdbClient disconnected from {} on port {} clientCn {} key {} ", remoteHost, localPort,
|
||||
clientCn, key);
|
||||
LOG.info("ovsdbClient connectedClients = {}",
|
||||
ConnectusOvsdbClient.this.ovsdbSessionMapInterface.getNumSessions());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
listener.startListeningWithSsl(ovsdbListenPort, sslContext, connectionCallback).join();
|
||||
|
||||
LOG.debug("manager waiting for connection on port {}...", ovsdbListenPort);
|
||||
}
|
||||
|
||||
private ConnectNodeInfo processConnectRequest(OvsdbClient ovsdbClient, String clientCn,
|
||||
ConnectNodeInfo connectNodeInfo) {
|
||||
|
||||
LOG.debug("Starting Client connect");
|
||||
connectNodeInfo = ovsdbDao.updateConnectNodeInfoOnConnect(ovsdbClient, clientCn, connectNodeInfo);
|
||||
|
||||
String apId = clientCn + "_" + connectNodeInfo.serialNumber;
|
||||
OpensyncAPConfig opensyncAPConfig = extIntegrationInterface.getApConfig(apId);
|
||||
|
||||
ovsdbDao.configureStats(ovsdbClient);
|
||||
|
||||
// Check if device stats is configured in Wifi_Stats_Config table,
|
||||
// provision it
|
||||
// if needed
|
||||
if (ovsdbDao.getDeviceStatsReportingInterval(ovsdbClient) != collectionIntervalSecDeviceStats) {
|
||||
ovsdbDao.updateDeviceStatsReportingInterval(ovsdbClient, collectionIntervalSecDeviceStats);
|
||||
}
|
||||
|
||||
try {
|
||||
ovsdbDao.provisionBridgePortInterface(ovsdbClient);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// TODO: for some AP configurations this 'may' not be necessary.
|
||||
LOG.warn("Could not provision Bridge->Port->Interface mapping.", e);
|
||||
}
|
||||
|
||||
ovsdbDao.removeAllSsids(ovsdbClient);
|
||||
|
||||
if (opensyncAPConfig != null) {
|
||||
ovsdbDao.configureWifiRadios(ovsdbClient, opensyncAPConfig);
|
||||
ovsdbDao.configureSsids(ovsdbClient, opensyncAPConfig);
|
||||
}
|
||||
|
||||
// ovsdbDao.configureWifiInet(ovsdbClient);
|
||||
|
||||
LOG.debug("Client connect Done");
|
||||
return connectNodeInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getConnectedClientIds() {
|
||||
return ovsdbSessionMapInterface.getConnectedClientIds();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param apId
|
||||
* @param newRedirectorAddress
|
||||
* @return updated value of the redirector
|
||||
*/
|
||||
@Override
|
||||
public String changeRedirectorAddress(String apId, String newRedirectorAddress) {
|
||||
OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId);
|
||||
if (ovsdbSession == null) {
|
||||
throw new IllegalStateException("AP with id " + apId + " is not connected");
|
||||
}
|
||||
|
||||
String ret = ovsdbDao.changeRedirectorAddress(ovsdbSession.getOvsdbClient(), apId, newRedirectorAddress);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processConfigChanged(String apId) {
|
||||
LOG.debug("Starting processConfigChanged for {}", apId);
|
||||
|
||||
OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId);
|
||||
if (ovsdbSession == null) {
|
||||
throw new IllegalStateException("AP with id " + apId + " is not connected");
|
||||
}
|
||||
|
||||
OvsdbClient ovsdbClient = ovsdbSession.getOvsdbClient();
|
||||
OpensyncAPConfig opensyncAPConfig = extIntegrationInterface.getApConfig(apId);
|
||||
|
||||
if (opensyncAPConfig != null) {
|
||||
ovsdbDao.removeAllSsids(ovsdbClient);
|
||||
ovsdbDao.configureWifiRadios(ovsdbClient, opensyncAPConfig);
|
||||
ovsdbDao.configureSsids(ovsdbClient, opensyncAPConfig);
|
||||
}
|
||||
|
||||
LOG.debug("Finished processConfigChanged for {}", apId);
|
||||
}
|
||||
|
||||
private void monitorOvsdbStateTables(OvsdbClient ovsdbClient, String key) throws OvsdbClientException {
|
||||
CompletableFuture<TableUpdates> rsCf = ovsdbClient.monitor(OvsdbDao.ovsdbName,
|
||||
OvsdbDao.wifiRadioStateDbTable + "_" + key,
|
||||
new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiRadioStateDbTable,
|
||||
new MonitorRequest(new MonitorSelect(true, false, false, true)))),
|
||||
new MonitorCallback() {
|
||||
|
||||
@Override
|
||||
public void update(TableUpdates tableUpdates) {
|
||||
extIntegrationInterface.wifiRadioStatusDbTableUpdate(
|
||||
ovsdbDao.getOpensyncAPRadioState(tableUpdates, key, ovsdbClient), key);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
extIntegrationInterface
|
||||
.wifiRadioStatusDbTableUpdate(ovsdbDao.getOpensyncAPRadioState(rsCf.join(), key, ovsdbClient), key);
|
||||
|
||||
CompletableFuture<TableUpdates> isCf = ovsdbClient.monitor(OvsdbDao.ovsdbName,
|
||||
OvsdbDao.wifiInetStateDbTable + "_" + key,
|
||||
new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiInetStateDbTable,
|
||||
new MonitorRequest(new MonitorSelect(true, true, true, true)))),
|
||||
new MonitorCallback() {
|
||||
|
||||
@Override
|
||||
public void update(TableUpdates tableUpdates) {
|
||||
|
||||
extIntegrationInterface.wifiInetStateDbTableUpdate(
|
||||
ovsdbDao.getOpensyncAPInetState(tableUpdates, key, ovsdbClient), key);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
extIntegrationInterface
|
||||
.wifiInetStateDbTableUpdate(ovsdbDao.getOpensyncAPInetState(isCf.join(), key, ovsdbClient), key);
|
||||
|
||||
CompletableFuture<TableUpdates> vsCf = ovsdbClient.monitor(OvsdbDao.ovsdbName,
|
||||
OvsdbDao.wifiVifStateDbTable + "_" + key,
|
||||
new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiVifStateDbTable,
|
||||
new MonitorRequest(new MonitorSelect(true, true, true, true)))),
|
||||
new MonitorCallback() {
|
||||
@Override
|
||||
public void update(TableUpdates tableUpdates) {
|
||||
// extIntegrationInterface.wifiVIFStateDbTableUpdate(
|
||||
// ovsdbDao.getOpensyncAPVIFState(tableUpdates,
|
||||
// key, ovsdbClient), key);
|
||||
List<OpensyncAPVIFState> vifsToDelete = new ArrayList<>();
|
||||
for (Entry<String, TableUpdate> tableUpdate : tableUpdates.getTableUpdates().entrySet()) {
|
||||
|
||||
for (Entry<UUID, RowUpdate> rowUpdate : tableUpdate.getValue().getRowUpdates().entrySet()) {
|
||||
if (rowUpdate.getValue().getOld() != null && rowUpdate.getValue().getNew() == null) {
|
||||
Row row = rowUpdate.getValue().getOld();
|
||||
String ifName = null;
|
||||
String ssid = null;
|
||||
if (row.getColumns().get("ssid") != null && row.getColumns().get("ssid").getClass()
|
||||
.equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) {
|
||||
ssid = row.getStringColumn("ssid");
|
||||
}
|
||||
if (row.getColumns().get("if_name") != null
|
||||
&& row.getColumns().get("if_name").getClass()
|
||||
.equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) {
|
||||
ifName = row.getStringColumn("if_name");
|
||||
}
|
||||
if (ifName != null && ssid != null) {
|
||||
OpensyncAPVIFState toBeDeleted = new OpensyncAPVIFState();
|
||||
toBeDeleted.setSsid(ssid);
|
||||
toBeDeleted.setIfName(ifName);
|
||||
vifsToDelete.add(toBeDeleted);
|
||||
}
|
||||
tableUpdate.getValue().getRowUpdates().remove(rowUpdate.getKey());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (tableUpdate.getValue().getRowUpdates().values().isEmpty()) {
|
||||
tableUpdates.getTableUpdates().remove(tableUpdate.getKey());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!vifsToDelete.isEmpty()) {
|
||||
extIntegrationInterface.wifiVIFStateDbTableDelete(vifsToDelete, key);
|
||||
}
|
||||
if (tableUpdates.getTableUpdates().entrySet().isEmpty()) {
|
||||
extIntegrationInterface.wifiVIFStateDbTableUpdate(
|
||||
ovsdbDao.getOpensyncAPVIFState(tableUpdates, key, ovsdbClient), key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
extIntegrationInterface.wifiVIFStateDbTableUpdate(ovsdbDao.getOpensyncAPVIFState(vsCf.join(), key, ovsdbClient),
|
||||
key);
|
||||
|
||||
CompletableFuture<TableUpdates> acCf = ovsdbClient.monitor(OvsdbDao.ovsdbName,
|
||||
OvsdbDao.wifiAssociatedClientsDbTable + "_" + key,
|
||||
new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiAssociatedClientsDbTable,
|
||||
new MonitorRequest(new MonitorSelect(false, true, true, true)))),
|
||||
new MonitorCallback() {
|
||||
|
||||
@Override
|
||||
public void update(TableUpdates tableUpdates) {
|
||||
|
||||
boolean insertOrModify = false;
|
||||
for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) {
|
||||
|
||||
for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) {
|
||||
if (rowUpdate.getOld() != null && rowUpdate.getNew() == null) {
|
||||
insertOrModify = false;
|
||||
Row row = rowUpdate.getOld();
|
||||
String deletedClientMac = row.getStringColumn("mac");
|
||||
extIntegrationInterface.wifiAssociatedClientsDbTableDelete(deletedClientMac, key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (insertOrModify) {
|
||||
extIntegrationInterface.wifiAssociatedClientsDbTableUpdate(
|
||||
ovsdbDao.getOpensyncWifiAssociatedClients(tableUpdates, key, ovsdbClient), key);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
extIntegrationInterface.wifiAssociatedClientsDbTableUpdate(
|
||||
ovsdbDao.getOpensyncWifiAssociatedClients(acCf.join(), key, ovsdbClient), key);
|
||||
|
||||
CompletableFuture<TableUpdates> awCf = ovsdbClient.monitor(
|
||||
OvsdbDao.ovsdbName, OvsdbDao.awlanNodeDbTable + "_" + key, new MonitorRequests(ImmutableMap
|
||||
.of(OvsdbDao.awlanNodeDbTable, new MonitorRequest(new MonitorSelect(true, false, false, true)))),
|
||||
new MonitorCallback() {
|
||||
|
||||
@Override
|
||||
public void update(TableUpdates tableUpdates) {
|
||||
extIntegrationInterface.awlanNodeDbTableUpdate(
|
||||
ovsdbDao.getOpensyncAWLANNode(tableUpdates, key, ovsdbClient), key);
|
||||
}
|
||||
|
||||
});
|
||||
extIntegrationInterface.awlanNodeDbTableUpdate(ovsdbDao.getOpensyncAWLANNode(awCf.join(), key, ovsdbClient),
|
||||
key);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String closeSession(String apId) {
|
||||
OvsdbSession session = ovsdbSessionMapInterface.getSession(apId);
|
||||
try {
|
||||
session.getOvsdbClient().shutdown();
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.error("Failed to close session to " + apId + " " + e.getLocalizedMessage());
|
||||
return "Failed to close session to " + apId + " " + e.getLocalizedMessage();
|
||||
|
||||
}
|
||||
LOG.debug("Closed session to " + apId);
|
||||
return "Closed session to " + apId;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user