ovsdb interface for client dhcp attributes -- first drop -> register for status changes

This commit is contained in:
Mike Hansen
2020-08-27 14:54:06 -04:00
parent 7204ec9abe
commit 1c8f7f9e53

View File

@@ -2,7 +2,9 @@ package com.telecominfraproject.wlan.opensync.ovsdb;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@@ -38,6 +40,7 @@ import com.vmware.ovsdb.protocol.methods.RowUpdate;
import com.vmware.ovsdb.protocol.methods.TableUpdate; import com.vmware.ovsdb.protocol.methods.TableUpdate;
import com.vmware.ovsdb.protocol.methods.TableUpdates; import com.vmware.ovsdb.protocol.methods.TableUpdates;
import com.vmware.ovsdb.protocol.operation.notation.Row; import com.vmware.ovsdb.protocol.operation.notation.Row;
import com.vmware.ovsdb.protocol.operation.notation.Value;
import com.vmware.ovsdb.service.OvsdbClient; import com.vmware.ovsdb.service.OvsdbClient;
import com.vmware.ovsdb.service.OvsdbPassiveConnectionListener; import com.vmware.ovsdb.service.OvsdbPassiveConnectionListener;
@@ -78,6 +81,7 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
public void listenForConnections() { public void listenForConnections() {
ConnectionCallback connectionCallback = new ConnectionCallback() { ConnectionCallback connectionCallback = new ConnectionCallback() {
@Override @Override
public void connected(OvsdbClient ovsdbClient) { public void connected(OvsdbClient ovsdbClient) {
@@ -333,25 +337,107 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
try { try {
monitorAwlanNodeDbTable(ovsdbClient, key); monitorAwlanNodeDbTable(ovsdbClient, key);
} catch (OvsdbClientException e) { } catch (OvsdbClientException e) {
LOG.debug("Could not enable monitor for deletions to AWLAN_Node table. {}", e.getMessage()); LOG.debug("Could not enable monitor for AWLAN_Node table. {}", e.getMessage());
}
try {
monitorDhcpLeasedIpDbTable(ovsdbClient, key);
} catch (OvsdbClientException e) {
LOG.debug("Could not enable monitor for DHCP_leased_IP table. {}", e.getMessage());
} }
LOG.debug("Finished (re)setting monitors for AP {}", key); LOG.debug("Finished (re)setting monitors for AP {}", key);
} }
private void monitorAwlanNodeDbTable(OvsdbClient ovsdbClient, String key) throws OvsdbClientException { private void monitorDhcpLeasedIpDbTable(OvsdbClient ovsdbClient, String key) throws OvsdbClientException {
CompletableFuture<TableUpdates> awCf = ovsdbClient
.monitor(OvsdbDao.ovsdbName, OvsdbDao.awlanNodeDbTable + "_" + key, CompletableFuture<TableUpdates> awCf = ovsdbClient.monitor(OvsdbDao.ovsdbName,
new MonitorRequests(ImmutableMap.of(OvsdbDao.awlanNodeDbTable, OvsdbDao.dhcpLeasedIpDbTable + "_" + key,
new MonitorRequest())), new MonitorRequests(ImmutableMap.of(OvsdbDao.dhcpLeasedIpDbTable, new MonitorRequest())),
new MonitorCallback() { new MonitorCallback() {
@Override @Override
public void update(TableUpdates tableUpdates) { public void update(TableUpdates tableUpdates) {
LOG.info(OvsdbDao.awlanNodeDbTable + "_" + key + " monitor callback received {}", LOG.info(OvsdbDao.dhcpLeasedIpDbTable + "_" + key + " monitor callback received {}",
tableUpdates); tableUpdates);
List<Map<String, String>> insert = new ArrayList<>();
List<Map<String, String>> delete = new ArrayList<>();
List<Map<String, String>> update = new ArrayList<>();
for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) {
for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) {
if (rowUpdate.getNew() == null) {
Map<String, String> rowMap = new HashMap<>();
rowUpdate.getOld().getColumns().entrySet().stream().forEach(c -> {
rowMap.put(c.getKey(), c.getValue().toString());
});
delete.add(rowMap);
// delete
} else if (rowUpdate.getOld() == null) {
// insert
Map<String, String> rowMap = new HashMap<>();
rowUpdate.getNew().getColumns().entrySet().stream().forEach(c -> {
rowMap.put(c.getKey(), c.getValue().toString());
});
insert.add(rowMap);
} else {
// insert
Map<String, String> rowMap = new HashMap<>();
rowUpdate.getOld().getColumns().putAll(rowUpdate.getNew().getColumns());
rowUpdate.getOld().getColumns().entrySet().stream().forEach(c -> {
rowMap.put(c.getKey(), c.getValue().toString());
});
update.add(rowMap);
}
}
}
// -- mikehansen1970 --
//TODO: when AP has schema and functionality in place to support it's
// additional attributes this will be enhanced to either
// follow the same approach as the other table state
// changes, in which case an additional model will be
// defined in the opensync-ext-interface project along
// with appropriate interface methods to handle changes.
// Alternatively this may be handled in the events from
// the AP when that comes online.
LOG.debug("insert {}", insert);
LOG.debug("delete {}", delete);
LOG.debug("modify {}", update);
}
});
awCf.join();
}
private void monitorAwlanNodeDbTable(OvsdbClient ovsdbClient, String key) throws OvsdbClientException {
CompletableFuture<TableUpdates> awCf = ovsdbClient.monitor(OvsdbDao.ovsdbName,
OvsdbDao.awlanNodeDbTable + "_" + key,
new MonitorRequests(ImmutableMap.of(OvsdbDao.awlanNodeDbTable, new MonitorRequest())),
new MonitorCallback() {
@Override
public void update(TableUpdates tableUpdates) {
LOG.info(OvsdbDao.awlanNodeDbTable + "_" + key + " monitor callback received {}", tableUpdates);
extIntegrationInterface.awlanNodeDbTableUpdate( extIntegrationInterface.awlanNodeDbTableUpdate(
ovsdbDao.getOpensyncAWLANNode(tableUpdates, key, ovsdbClient), key); ovsdbDao.getOpensyncAWLANNode(tableUpdates, key, ovsdbClient), key);
} }
@@ -363,17 +449,16 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
} }
private void monitorWifiAssociatedClientsDbTable(OvsdbClient ovsdbClient, String key) throws OvsdbClientException { private void monitorWifiAssociatedClientsDbTable(OvsdbClient ovsdbClient, String key) throws OvsdbClientException {
CompletableFuture<TableUpdates> acCf = ovsdbClient CompletableFuture<TableUpdates> acCf = ovsdbClient.monitor(OvsdbDao.ovsdbName,
.monitor(OvsdbDao.ovsdbName, OvsdbDao.wifiAssociatedClientsDbTable + "_" + key, OvsdbDao.wifiAssociatedClientsDbTable + "_" + key,
new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiAssociatedClientsDbTable, new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiAssociatedClientsDbTable, new MonitorRequest())),
new MonitorRequest())),
new MonitorCallback() { new MonitorCallback() {
@Override @Override
public void update(TableUpdates tableUpdates) { public void update(TableUpdates tableUpdates) {
LOG.info(OvsdbDao.wifiAssociatedClientsDbTable + "_" + key LOG.info(OvsdbDao.wifiAssociatedClientsDbTable + "_" + key + " monitor callback received {}",
+ " monitor callback received {}", tableUpdates); tableUpdates);
List<OpensyncWifiAssociatedClients> associatedClients = new ArrayList<>(); List<OpensyncWifiAssociatedClients> associatedClients = new ArrayList<>();
@@ -383,11 +468,13 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
if ((rowUpdate.getOld() != null) && (rowUpdate.getNew() == null)) { if ((rowUpdate.getOld() != null) && (rowUpdate.getNew() == null)) {
Row row = rowUpdate.getOld(); Row row = rowUpdate.getOld();
String deletedClientMac = row.getStringColumn("mac"); String deletedClientMac = row.getStringColumn("mac");
// take care of the deletes as we go through the updates, as we want to delete before adding anyway. // take care of the deletes as we go through
extIntegrationInterface.wifiAssociatedClientsDbTableDelete(deletedClientMac, // the updates, as we want to delete before
key); // adding anyway.
extIntegrationInterface.wifiAssociatedClientsDbTableDelete(deletedClientMac, key);
} else { } else {
associatedClients.addAll(ovsdbDao.getOpensyncWifiAssociatedClients(rowUpdate, key, ovsdbClient)); associatedClients.addAll(
ovsdbDao.getOpensyncWifiAssociatedClients(rowUpdate, key, ovsdbClient));
} }
} }
@@ -427,9 +514,11 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) { for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) {
if (rowUpdate.getNew() == null) { if (rowUpdate.getNew() == null) {
inetStateDelete.addAll(ovsdbDao.getOpensyncApInetStateForRowUpdate(rowUpdate, key, ovsdbClient)); inetStateDelete.addAll(ovsdbDao
.getOpensyncApInetStateForRowUpdate(rowUpdate, key, ovsdbClient));
} else { } else {
inetStateInsertOrUpdate.addAll(ovsdbDao.getOpensyncApInetStateForRowUpdate(rowUpdate, key, ovsdbClient)); inetStateInsertOrUpdate.addAll(ovsdbDao
.getOpensyncApInetStateForRowUpdate(rowUpdate, key, ovsdbClient));
} }
} }
@@ -437,12 +526,10 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
// delete first // delete first
extIntegrationInterface.wifiInetStateDbTableUpdate( extIntegrationInterface.wifiInetStateDbTableUpdate(inetStateDelete, key);
inetStateDelete, key);
// now process updates and mutations // now process updates and mutations
extIntegrationInterface.wifiInetStateDbTableUpdate( extIntegrationInterface.wifiInetStateDbTableUpdate(inetStateInsertOrUpdate, key);
inetStateInsertOrUpdate, key);
} }
@@ -453,10 +540,9 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
private void monitorWifiRadioStateDbTable(OvsdbClient ovsdbClient, String key) throws OvsdbClientException { private void monitorWifiRadioStateDbTable(OvsdbClient ovsdbClient, String key) throws OvsdbClientException {
CompletableFuture<TableUpdates> rsCf = ovsdbClient CompletableFuture<TableUpdates> rsCf = ovsdbClient.monitor(OvsdbDao.ovsdbName,
.monitor(OvsdbDao.ovsdbName, OvsdbDao.wifiRadioStateDbTable + "_" + key, OvsdbDao.wifiRadioStateDbTable + "_" + key,
new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiRadioStateDbTable, new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiRadioStateDbTable, new MonitorRequest())),
new MonitorRequest())),
new MonitorCallback() { new MonitorCallback() {
@Override @Override
@@ -475,11 +561,11 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
private void monitorWifiVifStateDbTable(OvsdbClient ovsdbClient, String key) throws OvsdbClientException { private void monitorWifiVifStateDbTable(OvsdbClient ovsdbClient, String key) throws OvsdbClientException {
CompletableFuture<TableUpdates> vsCf = ovsdbClient CompletableFuture<TableUpdates> vsCf = ovsdbClient.monitor(OvsdbDao.ovsdbName,
.monitor(OvsdbDao.ovsdbName, OvsdbDao.wifiVifStateDbTable + "_" + key, OvsdbDao.wifiVifStateDbTable + "_" + key,
new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiVifStateDbTable, new MonitorRequests(ImmutableMap.of(OvsdbDao.wifiVifStateDbTable, new MonitorRequest())),
new MonitorRequest())),
new MonitorCallback() { new MonitorCallback() {
@Override @Override
public void update(TableUpdates tableUpdates) { public void update(TableUpdates tableUpdates) {
LOG.info(OvsdbDao.wifiVifStateDbTable + "_" + key + " monitor callback received {}", LOG.info(OvsdbDao.wifiVifStateDbTable + "_" + key + " monitor callback received {}",
@@ -517,8 +603,6 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
} }
} }
}); });