Update reported IpV4 address for wan interface based on the value in the

Wifi_Inet_Table when the table state changes. Handles situation where
the AP connects before it's services are up and the table is not
populated with the IPs of the wan/lan interfaces.

Ensure dhcp_sniff is set on all interfaces.
This commit is contained in:
Mike Hansen
2020-10-29 15:01:05 -04:00
parent 7ef59937f2
commit 4df03431ed
3 changed files with 1998 additions and 1963 deletions

View File

@@ -1,5 +1,6 @@
package com.telecominfraproject.wlan.opensync.external.integration;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
@@ -148,6 +149,14 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
private boolean isAutoconfigEnabled;
@Value("${tip.wlan.ovsdb.defaultFwVersion:r10947-65030d81f3}")
private String defaultFwVersion;
@org.springframework.beans.factory.annotation.Value("${tip.wlan.ovsdb.wifi-iface.default_lan_type:bridge}")
public String defaultLanInterfaceType;
@org.springframework.beans.factory.annotation.Value("${tip.wlan.ovsdb.wifi-iface.default_lan_name:lan}")
public String defaultLanInterfaceName;
@org.springframework.beans.factory.annotation.Value("${tip.wlan.ovsdb.wifi-iface.default_wan_type:bridge}")
public String defaultWanInterfaceType;
@org.springframework.beans.factory.annotation.Value("${tip.wlan.ovsdb.wifi-iface.default_wan_name:wan}")
public String defaultWanInterfaceName;
@Autowired
private CacheManager cacheManagerShortLived;
@@ -500,9 +509,12 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
protocolStatusData.setReportedSwVersion("Unknown");
}
try {
if (connectNodeInfo.ipV4Address != null) {
protocolStatusData.setReportedIpV4Addr(InetAddress.getByName(connectNodeInfo.ipV4Address));
}
} catch (UnknownHostException e) {
// do nothing here
LOG.error("Could not set IpV4Addr {} on AP {} due to UnknownHostException ",
connectNodeInfo.ipV4Address, ce.getName(), e);
}
if ((connectNodeInfo.macAddress != null) && (MacAddress.valueOf(connectNodeInfo.macAddress) != null)) {
protocolStatusData.setReportedMacAddr(MacAddress.valueOf(connectNodeInfo.macAddress));
@@ -511,7 +523,8 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
protocolStatusData.setSerialNumber(connectNodeInfo.serialNumber);
protocolStatusData.setSystemName(connectNodeInfo.model);
statusRecord.setDetails(protocolStatusData);
statusServiceInterface.update(statusRecord);
Status protocolStatus = statusServiceInterface.update(statusRecord);
LOG.debug("ProtocolStatus for AP {} updated to {}", ce.getName(), protocolStatus);
statusRecord = statusServiceInterface.getOrNull(ce.getCustomerId(), ce.getId(), StatusDataType.FIRMWARE);
if (statusRecord == null) {
@@ -1139,6 +1152,8 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
Status activeBssidsStatus = statusServiceInterface.getOrNull(customerId, equipmentId,
StatusDataType.ACTIVE_BSSIDS);
statusServiceInterface.getForCustomer(customerId, null, ImmutableSet.of(StatusDataType.ACTIVE_BSSIDS), null,
null);
if (activeBssidsStatus == null) {
activeBssidsStatus = new Status();
activeBssidsStatus.setCustomerId(customerId);
@@ -1230,8 +1245,40 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
}
EquipmentLANStatusData lanStatusData = (EquipmentLANStatusData) lanStatus.getDetails();
Status protocolStatus = statusServiceInterface.getOrNull(customerId, equipmentId, StatusDataType.PROTOCOL);
if (protocolStatus == null) {
protocolStatus = new Status();
protocolStatus.setCustomerId(customerId);
protocolStatus.setEquipmentId(equipmentId);
protocolStatus.setStatusDataType(StatusDataType.PROTOCOL);
protocolStatus.setDetails(new EquipmentProtocolStatusData());
protocolStatus = statusServiceInterface.update(protocolStatus);
}
EquipmentProtocolStatusData protocolStatusData = (EquipmentProtocolStatusData) protocolStatus.getDetails();
for (OpensyncAPInetState inetState : inetStateTables) {
if (inetState.ifName != null && inetState.ifName.equals(defaultWanInterfaceName)) {
if (inetState.inetAddr != null) {
try {
protocolStatusData.setReportedIpV4Addr(Inet4Address.getByName(inetState.inetAddr));
protocolStatus.setDetails(protocolStatusData);
protocolStatus = statusServiceInterface.update(protocolStatus);
LOG.info("Updated IpV4Addr for AP {} to {} from Wifi_Inet_State change for if_name {}", apId,
((EquipmentProtocolStatusData) protocolStatus.getDetails()).getReportedIpV4Addr(), inetState.ifName);
LOG.debug("ProtocolStatus for AP {} updated to {}", apId, protocolStatus);
} catch (UnknownHostException e) {
LOG.error("Could not set IpV4Addr {} on AP {} due to UnknownHostException ", inetState.inetAddr,
apId, e);
}
}
}
if (inetState.getVlanId() > 1) {
if (!lanStatusData.getVlanStatusDataMap().containsKey(inetState.getVlanId())) {
@@ -1745,22 +1792,6 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
long locationId = ce.getLocationId();
//         "hwaddr":
//         "inet_addr":
//         "hostname":
//         "fingerprint":
//         "vendor_class":
//         "lease_time":
//         "subnet_mask":
//         "gateway":
//         "dhcp_server":
//         "primary_dns":
//         "secondary_dns":
//         "db_status":
//         "device_name":
//         "device_type":
//         "manuf_id":
if (rowUpdateOperation.equals(RowUpdateOperation.INSERT)) {
List<ClientSession> clientSessionList = new ArrayList<>();
@@ -1775,20 +1806,23 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
MacAddress clientMacAddress = new MacAddress(dhcpLeasedIps.get("hwaddr"));
if (clientMacAddress.equals(equipmentServiceInterface.get(equipmentId).getBaseMacAddress())) {
LOG.info("Not a client device {} ", dhcpLeasedIps);
com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface.getOrNull(customerId,
clientMacAddress);
com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface
.getOrNull(customerId, clientMacAddress);
if (client != null) {
// In case somehow this equipment has accidentally been tagged as a client, remove
// In case somehow this equipment has accidentally been
// tagged as a client, remove
ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, clientMacAddress);
ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId,
clientMacAddress);
if (clientSession != null) {
LOG.info("Deleting invalid client session {}", clientServiceInterface.deleteSession(customerId, equipmentId, clientMacAddress));
LOG.info("Deleting invalid client session {}",
clientServiceInterface.deleteSession(customerId, equipmentId, clientMacAddress));
}
LOG.info("Deleting invalid client {}", clientServiceInterface.delete(customerId, clientMacAddress));
LOG.info("Deleting invalid client {}",
clientServiceInterface.delete(customerId, clientMacAddress));
}
continue;
@@ -1878,6 +1912,13 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
LOG.info("Created Client {}.", client);
}
// we might have a session, update if required
ClientSession session = updateClientSession(customerId, equipmentId, locationId, dhcpLeasedIps,
clientMacAddress);
if (session != null) {
clientSessionList.add(session);
}
}
if (!clientSessionList.isEmpty()) {
@@ -1905,20 +1946,23 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
if (clientMacAddress.equals(equipmentServiceInterface.get(equipmentId).getBaseMacAddress())) {
LOG.info("Not a client device {} ", dhcpLeasedIps);
com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface.getOrNull(customerId,
clientMacAddress);
com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface
.getOrNull(customerId, clientMacAddress);
if (client != null) {
// In case somehow this equipment has accidentally been tagged as a client, remove
// In case somehow this equipment has accidentally been
// tagged as a client, remove
ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, clientMacAddress);
ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId,
clientMacAddress);
if (clientSession != null) {
LOG.info("Deleting invalid client session {}", clientServiceInterface.deleteSession(customerId, equipmentId, clientMacAddress));
LOG.info("Deleting invalid client session {}",
clientServiceInterface.deleteSession(customerId, equipmentId, clientMacAddress));
}
LOG.info("Deleting invalid client {}", clientServiceInterface.delete(customerId, clientMacAddress));
LOG.info("Deleting invalid client {}",
clientServiceInterface.delete(customerId, clientMacAddress));
}
continue;

View File

@@ -132,7 +132,6 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
}
@Override
public void disconnected(OvsdbClient ovsdbClient) {
String remoteHost = ovsdbClient.getConnectionInfo().getRemoteAddress().getHostAddress();
@@ -192,22 +191,16 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
// connectedClients table
String apId = alterClientCnIfRequired(clientCn, connectNodeInfo);
LOG.debug("Client connect for AP {}", apId);
LOG.debug("Client {} connect for AP {}", clientCn, apId);
OpensyncAPConfig opensyncAPConfig = extIntegrationInterface.getApConfig(apId);
// try {
// ovsdbDao.provisionBridgePortInterface(ovsdbClient);
// } catch (Exception e) {
// LOG.warn("Could not provision Bridge->Port->Interface mapping.", e);
// }
ovsdbDao.removeAllStatsConfigs(ovsdbClient); // always
ovsdbDao.removeAllSsids(ovsdbClient); // always
ovsdbDao.removeWifiRrm(ovsdbClient);
OpensyncAPConfig opensyncAPConfig = extIntegrationInterface.getApConfig(apId);
if (opensyncAPConfig != null) {
ovsdbDao.configureWifiRadios(ovsdbClient, opensyncAPConfig);
ovsdbDao.configureInterfaces(ovsdbClient);
ovsdbDao.configureSsids(ovsdbClient, opensyncAPConfig);
ovsdbDao.configureWifiRrm(ovsdbClient, opensyncAPConfig);
if (opensyncAPConfig.getHotspotConfig() != null) {
@@ -219,10 +212,13 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
}
}
ovsdbDao.configureInterfaces(ovsdbClient);
if (ovsdbDao.getDeviceStatsReportingInterval(ovsdbClient) != collectionIntervalSecDeviceStats) {
ovsdbDao.updateDeviceStatsReportingInterval(ovsdbClient, collectionIntervalSecDeviceStats);
}
LOG.debug("Client connect Done");
return connectNodeInfo;
}
@@ -271,12 +267,13 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
ovsdbDao.removeAllStatsConfigs(ovsdbClient); // always
ovsdbDao.configureWifiRadios(ovsdbClient, opensyncAPConfig);
ovsdbDao.configureInterfaces(ovsdbClient);
ovsdbDao.configureSsids(ovsdbClient, opensyncAPConfig);
ovsdbDao.configureWifiRrm(ovsdbClient, opensyncAPConfig);
if (opensyncAPConfig.getHotspotConfig() != null) {
ovsdbDao.configureHotspots(ovsdbClient, opensyncAPConfig);
}
ovsdbDao.configureInterfaces(ovsdbClient);
ovsdbDao.configureStatsFromProfile(ovsdbClient, opensyncAPConfig);
if (ovsdbDao.getDeviceStatsReportingInterval(ovsdbClient) != collectionIntervalSecDeviceStats) {
ovsdbDao.updateDeviceStatsReportingInterval(ovsdbClient, collectionIntervalSecDeviceStats);
@@ -360,7 +357,8 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
CompletableFuture<TableUpdates> awCf = ovsdbClient.monitor(OvsdbDao.ovsdbName,
OvsdbDao.dhcpLeasedIpDbTable + "_" + key,
new MonitorRequests(ImmutableMap.of(OvsdbDao.dhcpLeasedIpDbTable, new MonitorRequest(new MonitorSelect(true, true, true, true)))),
new MonitorRequests(ImmutableMap.of(OvsdbDao.dhcpLeasedIpDbTable,
new MonitorRequest(new MonitorSelect(true, true, true, true)))),
new MonitorCallback() {
@Override
@@ -425,15 +423,12 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
}
});
awCf.join();
}
private void monitorCommandStateDbTable(OvsdbClient ovsdbClient, String key) throws OvsdbClientException {
CompletableFuture<TableUpdates> csCf = ovsdbClient.monitor(OvsdbDao.ovsdbName,
@@ -450,7 +445,6 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
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()) {
@@ -504,12 +498,10 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
}
});
csCf.join();
}
private void monitorAwlanNodeDbTable(OvsdbClient ovsdbClient, String key) throws OvsdbClientException {
@@ -564,7 +556,6 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
}
// now address the update/add
extIntegrationInterface.wifiAssociatedClientsDbTableUpdate(associatedClients, key);
@@ -574,12 +565,11 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
acCf.join();
}
private void monitorWifiInetStateDbTable(OvsdbClient ovsdbClient, String key) throws OvsdbClientException {
CompletableFuture<TableUpdates> isCf = ovsdbClient
.monitor(OvsdbDao.ovsdbName, OvsdbDao.wifiInetStateDbTable + "_" + 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() {
@@ -598,17 +588,16 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) {
if (rowUpdate.getNew() == null) {
inetStateDelete.addAll(ovsdbDao
.getOpensyncApInetStateForRowUpdate(rowUpdate, key, ovsdbClient));
inetStateDelete.addAll(
ovsdbDao.getOpensyncApInetStateForRowUpdate(rowUpdate, key, ovsdbClient));
} else {
inetStateInsertOrUpdate.addAll(ovsdbDao
.getOpensyncApInetStateForRowUpdate(rowUpdate, key, ovsdbClient));
inetStateInsertOrUpdate.addAll(
ovsdbDao.getOpensyncApInetStateForRowUpdate(rowUpdate, key, ovsdbClient));
}
}
}
// delete first
extIntegrationInterface.wifiInetStateDbTableUpdate(inetStateDelete, key);
@@ -686,7 +675,6 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
}
}
});
@@ -841,7 +829,6 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface {
return "failed to trigger a factory reset of AP " + apId;
}
}
public String alterClientCnIfRequired(String clientCn, ConnectNodeInfo connectNodeInfo) {

View File

@@ -2049,16 +2049,17 @@ public class OvsdbDao {
public void configureInterfaces(OvsdbClient ovsdbClient) {
configureWanInterfaces(ovsdbClient);
configureLanInterfaces(ovsdbClient);
configureWanInterfacesForDhcpSniffing(ovsdbClient);
configureLanInterfacesforDhcpSniffing(ovsdbClient);
}
private void configureLanInterfaces(OvsdbClient ovsdbClient) {
private void configureLanInterfacesforDhcpSniffing(OvsdbClient ovsdbClient) {
List<Operation> operations = new ArrayList<>();
Map<String, Value> updateColumns = new HashMap<>();
List<Condition> conditions = new ArrayList<>();
conditions.add(new Condition("if_name", Function.EQUALS, new Atom<>(defaultLanInterfaceName)));
conditions.add(new Condition("if_name", Function.NOT_EQUALS, new Atom<>(defaultWanInterfaceName)));
conditions.add(new Condition("parent_ifname", Function.NOT_EQUALS, new Atom<>(defaultWanInterfaceName)));
updateColumns.put("dhcp_sniff", new Atom<>(true));
Row row = new Row(updateColumns);
@@ -2079,11 +2080,13 @@ public class OvsdbDao {
}
private void configureWanInterfaces(OvsdbClient ovsdbClient) {
private void configureWanInterfacesForDhcpSniffing(OvsdbClient ovsdbClient) {
List<Operation> operations = new ArrayList<>();
Map<String, Value> updateColumns = new HashMap<>();
List<Condition> conditions = new ArrayList<>();
conditions.add(new Condition("if_name", Function.EQUALS, new Atom<>(defaultWanInterfaceName)));
conditions.add(new Condition("if_name", Function.NOT_EQUALS, new Atom<>(defaultLanInterfaceName)));
conditions.add(new Condition("parent_ifname", Function.NOT_EQUALS, new Atom<>(defaultLanInterfaceName)));
updateColumns.put("dhcp_sniff", new Atom<>(true));
Row row = new Row(updateColumns);
@@ -3359,6 +3362,7 @@ public class OvsdbDao {
tableColumns.put("network", new Atom<>(true));
tableColumns.put("if_name", new Atom<>(ifName));
tableColumns.put("NAT", new Atom<>(isNat));
tableColumns.put("dhcp_sniff", new Atom<>(true));
Row row = new Row(tableColumns);
if (isUpdate) {