mirror of
				https://github.com/Telecominfraproject/wlan-cloud-opensync-controller.git
				synced 2025-11-04 04:27:59 +00:00 
			
		
		
		
	TW-208: Config and Metric params
This commit is contained in:
		@@ -0,0 +1,80 @@
 | 
			
		||||
package com.telecominfraproject.wlan.opensync.ovsdb;
 | 
			
		||||
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
import org.slf4j.Logger;
 | 
			
		||||
import org.slf4j.LoggerFactory;
 | 
			
		||||
 | 
			
		||||
import com.telecominfraproject.wlan.opensync.ovsdb.dao.OvsdbDao;
 | 
			
		||||
import com.vmware.ovsdb.callback.MonitorCallback;
 | 
			
		||||
import com.vmware.ovsdb.protocol.methods.RowUpdate;
 | 
			
		||||
import com.vmware.ovsdb.protocol.methods.TableUpdates;
 | 
			
		||||
import com.vmware.ovsdb.protocol.operation.notation.Row;
 | 
			
		||||
import com.vmware.ovsdb.service.OvsdbClient;
 | 
			
		||||
 | 
			
		||||
public class ConnectusMonitorCallback implements MonitorCallback {
 | 
			
		||||
 | 
			
		||||
	private OvsdbClient ovsdbClient;
 | 
			
		||||
	private String connectedClientId;
 | 
			
		||||
 | 
			
		||||
	private static final Logger LOG = LoggerFactory.getLogger(ConnectusMonitorCallback.class);
 | 
			
		||||
 | 
			
		||||
	public ConnectusMonitorCallback(OvsdbClient ovsdbClient, String clientId) {
 | 
			
		||||
		this.ovsdbClient = ovsdbClient;
 | 
			
		||||
		this.connectedClientId = clientId;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public void update(TableUpdates tableUpdates) {
 | 
			
		||||
		for (String key : tableUpdates.getTableUpdates().keySet()) {
 | 
			
		||||
 | 
			
		||||
			LOG.debug("Received update to table {} on AP {}", key,
 | 
			
		||||
					connectedClientId);
 | 
			
		||||
			
 | 
			
		||||
			if (key.equalsIgnoreCase(OvsdbDao.wifiInetStateDbTable)) {
 | 
			
		||||
				Map<UUID, RowUpdate> rowUpdates = tableUpdates.getTableUpdates().get(OvsdbDao.wifiInetStateDbTable)
 | 
			
		||||
						.getRowUpdates();
 | 
			
		||||
 | 
			
		||||
				for (UUID rowId : rowUpdates.keySet()) {
 | 
			
		||||
 | 
			
		||||
					logRow(rowUpdates, rowId);
 | 
			
		||||
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
			} else if (key.equalsIgnoreCase(OvsdbDao.wifiRadioStateDbTable)) {
 | 
			
		||||
				Map<UUID, RowUpdate> rowUpdates = tableUpdates.getTableUpdates().get(OvsdbDao.wifiRadioStateDbTable)
 | 
			
		||||
						.getRowUpdates();
 | 
			
		||||
 | 
			
		||||
				for (UUID rowId : rowUpdates.keySet()) {
 | 
			
		||||
 | 
			
		||||
					logRow(rowUpdates, rowId);
 | 
			
		||||
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
			} else if (key.equals(OvsdbDao.wifiVifStateDbTable)) {
 | 
			
		||||
				Map<UUID, RowUpdate> rowUpdates = tableUpdates.getTableUpdates().get(OvsdbDao.wifiVifStateDbTable)
 | 
			
		||||
						.getRowUpdates();
 | 
			
		||||
 | 
			
		||||
				for (UUID rowId : rowUpdates.keySet()) {
 | 
			
		||||
 | 
			
		||||
					logRow(rowUpdates, rowId);
 | 
			
		||||
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void logRow(Map<UUID, RowUpdate> rowUpdates, UUID rowId) {
 | 
			
		||||
		RowUpdate rowUpdate = rowUpdates.get(rowId);
 | 
			
		||||
		Row oldRow = rowUpdate.getOld();
 | 
			
		||||
		oldRow.getColumns().entrySet().stream()
 | 
			
		||||
				.forEach(e -> LOG.trace("Key {} Value {}", e.getKey(), e.getValue().toString()));
 | 
			
		||||
		Row newRow = rowUpdate.getNew();
 | 
			
		||||
		newRow.getColumns().entrySet().stream()
 | 
			
		||||
				.forEach(e -> LOG.trace("Key {} Value {}", e.getKey(), e.getValue().toString()));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -20,8 +20,6 @@ import com.telecominfraproject.wlan.opensync.external.integration.models.Opensyn
 | 
			
		||||
import com.telecominfraproject.wlan.opensync.ovsdb.dao.OvsdbDao;
 | 
			
		||||
import com.telecominfraproject.wlan.opensync.util.SslUtil;
 | 
			
		||||
import com.vmware.ovsdb.callback.ConnectionCallback;
 | 
			
		||||
import com.vmware.ovsdb.callback.MonitorCallback;
 | 
			
		||||
import com.vmware.ovsdb.protocol.methods.TableUpdates;
 | 
			
		||||
import com.vmware.ovsdb.service.OvsdbClient;
 | 
			
		||||
import com.vmware.ovsdb.service.OvsdbPassiveConnectionListener;
 | 
			
		||||
 | 
			
		||||
@@ -31,201 +29,192 @@ import io.netty.handler.ssl.SslContext;
 | 
			
		||||
@Component
 | 
			
		||||
public class ConnectusOvsdbClient implements ConnectusOvsdbClientInterface {
 | 
			
		||||
 | 
			
		||||
    private static final Logger LOG = LoggerFactory.getLogger(ConnectusOvsdbClient.class);
 | 
			
		||||
	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.ovsdb.listenPort:6640}")
 | 
			
		||||
    private int ovsdbListenPort;
 | 
			
		||||
	@org.springframework.beans.factory.annotation.Value("${connectus.manager.collectionIntervalSec.deviceStats:10}")
 | 
			
		||||
	private long collectionIntervalSecDeviceStats;
 | 
			
		||||
 | 
			
		||||
    @org.springframework.beans.factory.annotation.Value("${connectus.manager.collectionIntervalSec.deviceStats:10}")
 | 
			
		||||
    private long collectionIntervalSecDeviceStats;
 | 
			
		||||
	@Autowired
 | 
			
		||||
	private SslContext sslContext;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private SslContext sslContext;
 | 
			
		||||
	@Autowired
 | 
			
		||||
	private OvsdbPassiveConnectionListener listener;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private OvsdbPassiveConnectionListener listener;
 | 
			
		||||
	@Autowired
 | 
			
		||||
	private OvsdbDao ovsdbDao;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private OvsdbDao ovsdbDao;
 | 
			
		||||
	@Autowired
 | 
			
		||||
	private OpensyncExternalIntegrationInterface extIntegrationInterface;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private OpensyncExternalIntegrationInterface extIntegrationInterface;
 | 
			
		||||
	@Autowired
 | 
			
		||||
	private OvsdbSessionMapInterface ovsdbSessionMapInterface;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private OvsdbSessionMapInterface ovsdbSessionMapInterface;
 | 
			
		||||
	@PostConstruct
 | 
			
		||||
	private void postCreate() {
 | 
			
		||||
		listenForConnections();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    @PostConstruct
 | 
			
		||||
    private void postCreate() {
 | 
			
		||||
        listenForConnections();
 | 
			
		||||
    }
 | 
			
		||||
	public void listenForConnections() {
 | 
			
		||||
 | 
			
		||||
    public class ConnectusMonitorCallback implements MonitorCallback {
 | 
			
		||||
		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 clientCNKey;
 | 
			
		||||
					String clientCn = SslUtil.extractCN(subjectDn);
 | 
			
		||||
					LOG.info("ovsdbClient connecting from {} on port {} clientCn {}", remoteHost, localPort, clientCn);
 | 
			
		||||
 | 
			
		||||
    	public ConnectusMonitorCallback(String key) {
 | 
			
		||||
					ConnectNodeInfo connectNodeInfo = ovsdbDao.getConnectNodeInfo(ovsdbClient);
 | 
			
		||||
 | 
			
		||||
    		clientCNKey = key;
 | 
			
		||||
					// 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);
 | 
			
		||||
					LOG.info("ovsdbClient connected from {} on port {} key {} ", remoteHost, localPort, key);
 | 
			
		||||
					LOG.info("ovsdbClient connectedClients = {}",
 | 
			
		||||
							ConnectusOvsdbClient.this.ovsdbSessionMapInterface.getNumSessions());
 | 
			
		||||
 | 
			
		||||
		@Override
 | 
			
		||||
		public void update(TableUpdates tableUpdates) {
 | 
			
		||||
			LOG.info("Monitor for client key {} received table updates {}", clientCNKey, tableUpdates);
 | 
			
		||||
					// monitor radio config state
 | 
			
		||||
					ovsdbDao.monitorRadioConfigState(ovsdbClient, new ConnectusMonitorCallback(ovsdbClient, key));
 | 
			
		||||
					// monitor inet state
 | 
			
		||||
					ovsdbDao.monitorInetState(ovsdbClient, new ConnectusMonitorCallback(ovsdbClient, key));
 | 
			
		||||
					// monitor vif state
 | 
			
		||||
					ovsdbDao.monitorVIFState(ovsdbClient, new ConnectusMonitorCallback(ovsdbClient, key));
 | 
			
		||||
					// monitor Route state
 | 
			
		||||
					ovsdbDao.monitorRouteState(ovsdbClient, new ConnectusMonitorCallback(ovsdbClient, key));
 | 
			
		||||
					// monitor Master State
 | 
			
		||||
					ovsdbDao.monitorMasterState(ovsdbClient, new ConnectusMonitorCallback(ovsdbClient, key));
 | 
			
		||||
				} 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) {
 | 
			
		||||
					extIntegrationInterface.apDisconnected(key);
 | 
			
		||||
					ConnectusOvsdbClient.this.ovsdbSessionMapInterface.removeSession(key);
 | 
			
		||||
				}
 | 
			
		||||
				// turn off monitor
 | 
			
		||||
				ovsdbDao.cancelMonitors(ovsdbClient);
 | 
			
		||||
				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);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
		ovsdbDao.provisionBridgePortInterface(ovsdbClient);
 | 
			
		||||
 | 
			
		||||
		ovsdbDao.removeAllSsids(ovsdbClient);
 | 
			
		||||
 | 
			
		||||
    public void listenForConnections() {
 | 
			
		||||
		if (opensyncAPConfig != null) {
 | 
			
		||||
			ovsdbDao.configureWifiRadios(ovsdbClient, opensyncAPConfig.getRadioConfig());
 | 
			
		||||
			ovsdbDao.configureSsids(ovsdbClient, opensyncAPConfig.getSsidConfigs());
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
        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();
 | 
			
		||||
		ovsdbDao.configureWifiInet(ovsdbClient);
 | 
			
		||||
 | 
			
		||||
                    String clientCn = SslUtil.extractCN(subjectDn);
 | 
			
		||||
                    LOG.info("ovsdbClient connecting from {} on port {} clientCn {}", remoteHost, localPort, clientCn);                
 | 
			
		||||
		LOG.debug("Client connect Done");
 | 
			
		||||
		return connectNodeInfo;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
                    ConnectNodeInfo connectNodeInfo = ovsdbDao.getConnectNodeInfo(ovsdbClient);
 | 
			
		||||
	public Set<String> getConnectedClientIds() {
 | 
			
		||||
		return ovsdbSessionMapInterface.getConnectedClientIds();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
                    //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);
 | 
			
		||||
	/**
 | 
			
		||||
	 * @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");
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
                    //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());
 | 
			
		||||
		String ret = ovsdbDao.changeRedirectorAddress(ovsdbSession.getOvsdbClient(), apId, newRedirectorAddress);
 | 
			
		||||
 | 
			
		||||
                    // monitor radio config state
 | 
			
		||||
                    ovsdbDao.monitorRadioConfigState(ovsdbClient, new ConnectusMonitorCallback(key));
 | 
			
		||||
                    // monitor inet state
 | 
			
		||||
                    ovsdbDao.monitorInetState(ovsdbClient, new ConnectusMonitorCallback(key));
 | 
			
		||||
                    // monitor vif state
 | 
			
		||||
                    ovsdbDao.monitorVIFState(ovsdbClient, new ConnectusMonitorCallback(key));
 | 
			
		||||
                    // monitor Route state
 | 
			
		||||
                    ovsdbDao.monitorRouteState(ovsdbClient, new ConnectusMonitorCallback(key));
 | 
			
		||||
                   // monitor Master State
 | 
			
		||||
                    ovsdbDao.monitorMasterState(ovsdbClient, new ConnectusMonitorCallback(key));
 | 
			
		||||
                } catch (Exception e) {
 | 
			
		||||
                    LOG.error("ovsdbClient error", e);
 | 
			
		||||
                    //something is wrong with the SSL 
 | 
			
		||||
                    ovsdbClient.shutdown();
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
		return ret;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
            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
 | 
			
		||||
                }
 | 
			
		||||
	@Override
 | 
			
		||||
	public void processConfigChanged(String apId) {
 | 
			
		||||
		LOG.debug("Starting processConfigChanged for {}", apId);
 | 
			
		||||
 | 
			
		||||
                String clientCn = SslUtil.extractCN(subjectDn);
 | 
			
		||||
		OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId);
 | 
			
		||||
		if (ovsdbSession == null) {
 | 
			
		||||
			throw new IllegalStateException("AP with id " + apId + " is not connected");
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
                //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);
 | 
			
		||||
		OvsdbClient ovsdbClient = ovsdbSession.getOvsdbClient();
 | 
			
		||||
		OpensyncAPConfig opensyncAPConfig = extIntegrationInterface.getApConfig(apId);
 | 
			
		||||
 | 
			
		||||
                if(key!=null) {
 | 
			
		||||
                    extIntegrationInterface.apDisconnected(key);
 | 
			
		||||
                    ConnectusOvsdbClient.this.ovsdbSessionMapInterface.removeSession(key);
 | 
			
		||||
                }
 | 
			
		||||
                // turn off monitor
 | 
			
		||||
                ovsdbDao.cancelMonitors(ovsdbClient);
 | 
			
		||||
                ovsdbClient.shutdown();
 | 
			
		||||
		if (opensyncAPConfig != null) {
 | 
			
		||||
			ovsdbDao.removeAllSsids(ovsdbClient);
 | 
			
		||||
			ovsdbDao.configureWifiRadios(ovsdbClient, opensyncAPConfig.getRadioConfig());
 | 
			
		||||
			ovsdbDao.configureSsids(ovsdbClient, opensyncAPConfig.getSsidConfigs());
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
                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);
 | 
			
		||||
        }            
 | 
			
		||||
 | 
			
		||||
        ovsdbDao.provisionBridgePortInterface(ovsdbClient);
 | 
			
		||||
 | 
			
		||||
        ovsdbDao.removeAllSsids(ovsdbClient);
 | 
			
		||||
        
 | 
			
		||||
        if(opensyncAPConfig!=null) {
 | 
			
		||||
            ovsdbDao.configureWifiRadios(ovsdbClient, opensyncAPConfig.getRadioConfig());
 | 
			
		||||
            ovsdbDao.configureSsids(ovsdbClient, opensyncAPConfig.getSsidConfigs());
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        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.getRadioConfig());
 | 
			
		||||
            ovsdbDao.configureSsids(ovsdbClient, opensyncAPConfig.getSsidConfigs());
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        LOG.debug("Finished processConfigChanged for {}", apId);        
 | 
			
		||||
    }
 | 
			
		||||
		LOG.debug("Finished processConfigChanged for {}", apId);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -15,6 +15,7 @@ import org.slf4j.Logger;
 | 
			
		||||
import org.slf4j.LoggerFactory;
 | 
			
		||||
import org.springframework.stereotype.Component;
 | 
			
		||||
 | 
			
		||||
import com.google.common.collect.ImmutableMap;
 | 
			
		||||
import com.telecominfraproject.wlan.core.model.equipment.RadioType;
 | 
			
		||||
import com.telecominfraproject.wlan.opensync.external.integration.models.ConnectNodeInfo;
 | 
			
		||||
import com.telecominfraproject.wlan.opensync.external.integration.models.OpensyncAPRadioConfig;
 | 
			
		||||
@@ -103,14 +104,11 @@ public class OvsdbDao {
 | 
			
		||||
		columns.add("gateway_hwaddr");
 | 
			
		||||
		columns.add("if_name");
 | 
			
		||||
 | 
			
		||||
		MonitorRequest monitorRequest = new MonitorRequest(columns, new MonitorSelect(true,true,true,true));
 | 
			
		||||
 | 
			
		||||
		Map<String,MonitorRequest> monitorRequests = new HashMap<String, MonitorRequest>();
 | 
			
		||||
		monitorRequests.put(wifiRouteStateDbTable, monitorRequest);
 | 
			
		||||
		MonitorRequests requests = new MonitorRequests(monitorRequests) ;
 | 
			
		||||
 | 
			
		||||
		MonitorRequest monitorRequest = new MonitorRequest();
 | 
			
		||||
		MonitorRequests monitorRequests = new MonitorRequests(
 | 
			
		||||
				ImmutableMap.of(wifiRouteStateDbTable, monitorRequest));
 | 
			
		||||
		try {
 | 
			
		||||
			ovsdbClient.monitor(ovsdbName, wifiRouteStateDbTableMonitorId, requests, monitorCallback);
 | 
			
		||||
			ovsdbClient.monitor(ovsdbName, wifiRouteStateDbTableMonitorId, monitorRequests, monitorCallback);
 | 
			
		||||
		} catch (OvsdbClientException e) {
 | 
			
		||||
			LOG.error("Unable to add Monitor to table " + wifiRouteStateDbTable, e);
 | 
			
		||||
		}
 | 
			
		||||
@@ -129,14 +127,12 @@ public class OvsdbDao {
 | 
			
		||||
		columns.add("network_state");
 | 
			
		||||
		columns.add("port_state");
 | 
			
		||||
 | 
			
		||||
		MonitorRequest monitorRequest = new MonitorRequest(columns, new MonitorSelect(true,true,true,true));
 | 
			
		||||
 | 
			
		||||
		Map<String,MonitorRequest> monitorRequests = new HashMap<String, MonitorRequest>();
 | 
			
		||||
		monitorRequests.put(wifiMasterStateDbTable, monitorRequest);
 | 
			
		||||
		MonitorRequests requests = new MonitorRequests(monitorRequests) ;
 | 
			
		||||
		MonitorRequest monitorRequest = new MonitorRequest();
 | 
			
		||||
		MonitorRequests monitorRequests = new MonitorRequests(
 | 
			
		||||
				ImmutableMap.of(wifiMasterStateDbTable, monitorRequest));
 | 
			
		||||
 | 
			
		||||
		try {
 | 
			
		||||
			ovsdbClient.monitor(ovsdbName, wifiMasterStateDbTableMonitorId, requests, monitorCallback);
 | 
			
		||||
			ovsdbClient.monitor(ovsdbName, wifiMasterStateDbTableMonitorId, monitorRequests, monitorCallback);
 | 
			
		||||
		} catch (OvsdbClientException e) {
 | 
			
		||||
			LOG.error("Unable to add Monitor to table " + wifiMasterStateDbTable, e);
 | 
			
		||||
		}
 | 
			
		||||
@@ -165,14 +161,12 @@ public class OvsdbDao {
 | 
			
		||||
		columns.add("vif_config");
 | 
			
		||||
		columns.add("vif_radio_idx");
 | 
			
		||||
 | 
			
		||||
		MonitorRequest monitorRequest = new MonitorRequest(columns, new MonitorSelect(true,true,true,true));
 | 
			
		||||
 | 
			
		||||
		Map<String,MonitorRequest> monitorRequests = new HashMap<String, MonitorRequest>();
 | 
			
		||||
		monitorRequests.put(wifiVifStateDbTable, monitorRequest);
 | 
			
		||||
		MonitorRequests requests = new MonitorRequests(monitorRequests) ;
 | 
			
		||||
		MonitorRequest monitorRequest = new MonitorRequest();
 | 
			
		||||
		MonitorRequests monitorRequests = new MonitorRequests(
 | 
			
		||||
				ImmutableMap.of(wifiVifStateDbTable, monitorRequest));
 | 
			
		||||
 | 
			
		||||
		try {
 | 
			
		||||
			ovsdbClient.monitor(ovsdbName, wifiVifStateDbTableMonitorId, requests, monitorCallback);
 | 
			
		||||
			ovsdbClient.monitor(ovsdbName, wifiVifStateDbTableMonitorId, monitorRequests, monitorCallback);
 | 
			
		||||
		} catch (OvsdbClientException e) {
 | 
			
		||||
			LOG.error("Unable to add Monitor to table " + wifiVifStateDbTable, e);
 | 
			
		||||
		}
 | 
			
		||||
@@ -197,14 +191,12 @@ public class OvsdbDao {
 | 
			
		||||
		columns.add("network");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		MonitorRequest monitorRequest = new MonitorRequest(columns, new MonitorSelect(true,true,true,true));
 | 
			
		||||
 | 
			
		||||
		Map<String,MonitorRequest> monitorRequests = new HashMap<String, MonitorRequest>();
 | 
			
		||||
		monitorRequests.put(wifiInetStateDbTable, monitorRequest);
 | 
			
		||||
		MonitorRequests requests = new MonitorRequests(monitorRequests) ;
 | 
			
		||||
		MonitorRequest monitorRequest = new MonitorRequest();
 | 
			
		||||
		MonitorRequests monitorRequests = new MonitorRequests(
 | 
			
		||||
				ImmutableMap.of(wifiInetStateDbTable, monitorRequest));
 | 
			
		||||
 | 
			
		||||
		try {
 | 
			
		||||
			ovsdbClient.monitor(ovsdbName, wifiInetStateDbTableMonitorId, requests, monitorCallback);
 | 
			
		||||
			ovsdbClient.monitor(ovsdbName, wifiInetStateDbTableMonitorId, monitorRequests, monitorCallback);
 | 
			
		||||
		} catch (OvsdbClientException e) {
 | 
			
		||||
			LOG.error("Unable to add Monitor to table " + wifiInetStateDbTable, e);
 | 
			
		||||
		}
 | 
			
		||||
@@ -220,6 +212,8 @@ public class OvsdbDao {
 | 
			
		||||
			ovsdbClient.cancelMonitor(wifiVifStateDbTableMonitorId);
 | 
			
		||||
			ovsdbClient.cancelMonitor(wifiInetStateDbTableMonitorId);
 | 
			
		||||
			ovsdbClient.cancelMonitor(wifiRouteStateDbTableMonitorId);
 | 
			
		||||
			ovsdbClient.cancelMonitor(wifiMasterStateDbTableMonitorId);
 | 
			
		||||
 | 
			
		||||
		} catch (Exception e) {
 | 
			
		||||
			LOG.error("Caught Exception {}", e);
 | 
			
		||||
		} 
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user