diff --git a/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/TipWlanOvsdbClient.java b/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/TipWlanOvsdbClient.java index 71c3a26..a687dbf 100644 --- a/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/TipWlanOvsdbClient.java +++ b/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/TipWlanOvsdbClient.java @@ -200,10 +200,12 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { ovsdbDao.removeAllStatsConfigs(ovsdbClient); // always ovsdbDao.removeAllSsids(ovsdbClient, opensyncAPConfig); // always ovsdbDao.removeWifiRrm(ovsdbClient); + ovsdbDao.removeAllGreTunnels(ovsdbClient, opensyncAPConfig); ovsdbDao.configureWifiRadios(ovsdbClient, opensyncAPConfig); ovsdbDao.configureInterfaces(ovsdbClient); ovsdbDao.configureSsids(ovsdbClient, opensyncAPConfig); ovsdbDao.configureWifiRrm(ovsdbClient, opensyncAPConfig); + ovsdbDao.configureGreTunnels(ovsdbClient, opensyncAPConfig); if (opensyncAPConfig.getHotspotConfig() != null) { ovsdbDao.configureHotspots(ovsdbClient, opensyncAPConfig); } @@ -216,6 +218,7 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { ovsdbDao.removeAllStatsConfigs(ovsdbClient); // always ovsdbDao.removeAllSsids(ovsdbClient); // always ovsdbDao.removeWifiRrm(ovsdbClient); + ovsdbDao.removeAllGreTunnels(ovsdbClient, null); } if (ovsdbDao.getDeviceStatsReportingInterval(ovsdbClient) != collectionIntervalSecDeviceStats) { @@ -268,6 +271,7 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { ovsdbDao.removeAllPasspointConfigs(ovsdbClient); ovsdbDao.removeAllSsids(ovsdbClient, opensyncAPConfig); // always + ovsdbDao.removeAllGreTunnels(ovsdbClient, opensyncAPConfig); ovsdbDao.removeWifiRrm(ovsdbClient); ovsdbDao.removeAllStatsConfigs(ovsdbClient); // always @@ -275,6 +279,7 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { ovsdbDao.configureInterfaces(ovsdbClient); ovsdbDao.configureSsids(ovsdbClient, opensyncAPConfig); ovsdbDao.configureWifiRrm(ovsdbClient, opensyncAPConfig); + ovsdbDao.configureGreTunnels(ovsdbClient, opensyncAPConfig); if (opensyncAPConfig.getHotspotConfig() != null) { ovsdbDao.configureHotspots(ovsdbClient, opensyncAPConfig); } diff --git a/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbDao.java b/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbDao.java index 96c5654..d2bb3ca 100644 --- a/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbDao.java +++ b/opensync-gateway/src/main/java/com/telecominfraproject/wlan/opensync/ovsdb/dao/OvsdbDao.java @@ -66,6 +66,7 @@ import com.telecominfraproject.wlan.profile.bonjour.models.BonjourGatewayProfile import com.telecominfraproject.wlan.profile.bonjour.models.BonjourServiceSet; import com.telecominfraproject.wlan.profile.captiveportal.models.CaptivePortalAuthenticationType; import com.telecominfraproject.wlan.profile.captiveportal.models.CaptivePortalConfiguration; +import com.telecominfraproject.wlan.profile.gre.tunnels.GreTunnelProfile; import com.telecominfraproject.wlan.profile.metrics.ChannelUtilizationSurveyType; import com.telecominfraproject.wlan.profile.metrics.ServiceMetricConfigParameters; import com.telecominfraproject.wlan.profile.metrics.ServiceMetricRadioConfigParameters; @@ -1699,6 +1700,70 @@ public class OvsdbDao { } } + public void removeAllGreTunnels(OvsdbClient ovsdbClient, OpensyncAPConfig opensyncAPConfig) { + try { + List operations = new ArrayList<>(); + List conditions = new ArrayList<>(); + if (opensyncAPConfig == null || opensyncAPConfig.getGreTunnelProfiles() == null) { + conditions.add(new Condition("if_type", Function.EQUALS, new Atom<>("gre"))); + operations.add(new Delete(wifiInetConfigDbTable, conditions)); + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + if (LOG.isDebugEnabled()) { + + for (OperationResult res : result) { + LOG.debug("removeAllGreTunnels Op Result {}", res); + } + } + } else { + + Set greSet = new HashSet<>(); + opensyncAPConfig.getGreTunnelProfiles().stream().forEach(p -> { + GreTunnelProfile profileDetails = (GreTunnelProfile)p.getDetails(); + greSet.add(profileDetails.getGreTunnelName()); + }); + + conditions.add(new Condition("if_type", Function.EQUALS, new Atom<>("gre"))); + operations.add(new Select(wifiInetConfigDbTable, conditions)); + + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + + if (((SelectResult) result[0]).getRows().isEmpty()) { + LOG.debug("No Gre Tunnels present"); + return; + } else { + operations.clear(); + for (Row row : ((SelectResult) result[0]).getRows()) { + String ifName = row.getStringColumn("if_name"); + if (!greSet.contains(ifName)) { + List deleteCondition = new ArrayList<>(); + deleteCondition.add(new Condition("if_name", Function.EQUALS, new Atom<>(ifName))); + operations.add(new Delete(wifiInetConfigDbTable, deleteCondition)); + } + } + + } + + ovsdbClient.transact(ovsdbName, operations); + fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + + if (LOG.isDebugEnabled()) { + + for (OperationResult res : result) { + LOG.debug("removeAllGreTunnels Op Result {}", res); + } + } + + } + } catch (OvsdbClientException | InterruptedException | ExecutionException | TimeoutException e) { + LOG.error("Could not delete GreTunnel Configs", e); + throw new RuntimeException(e); + } + + + } + public void removeAllSsids(OvsdbClient ovsdbClient, OpensyncAPConfig opensyncAPConfig) { Map currentWifiVifConfigInfo = getProvisionedWifiVifConfigs(ovsdbClient); Map currentWifiRadioConfigInfo = getProvisionedWifiRadioConfigs(ovsdbClient); @@ -3191,6 +3256,66 @@ public class OvsdbDao { } + public void configureGreTunnels(OvsdbClient ovsdbClient, OpensyncAPConfig opensyncApConfig) { + + LOG.info("Configure Gre tunnels {}", opensyncApConfig.getGreTunnelProfiles()); + if (opensyncApConfig.getGreTunnelProfiles() != null) { + for (Profile greTunnel : opensyncApConfig.getGreTunnelProfiles()) { + configureGreTunnel(ovsdbClient, greTunnel); + } + } + + } + + private void configureGreTunnel(OvsdbClient ovsdbClient, Profile greTunnelProfile) { + try { + LOG.debug("Configure Gre Tunnel {}", greTunnelProfile); + List operations = new ArrayList<>(); + Map tableColumns = new HashMap<>(); + + GreTunnelProfile details = (GreTunnelProfile) greTunnelProfile.getDetails(); + tableColumns.put("gre_ifname", new Atom<>(defaultWanInterfaceName)); + tableColumns.put("gre_local_inet_addr", new Atom<>(details.getGreLocalInetAddr().getHostAddress())); + tableColumns.put("gre_remote_inet_addr", new Atom<>(details.getGreRemoteInetAddr().getHostAddress())); + if (details.getGreRemoteMacAddr() != null) { + tableColumns.put("gre_remote_mac_addr", + new Atom<>(details.getGreRemoteMacAddr().getAddressAsString())); + } + tableColumns.put("if_name", new Atom<>(details.getGreTunnelName())); + tableColumns.put("if_type", new Atom<>("gre")); + tableColumns.put("network", new Atom<>(true)); + tableColumns.put("NAT", new Atom<>(false)); + tableColumns.put("enabled", new Atom<>(true)); + + List conditions = new ArrayList<>(); + conditions.add(new Condition("if_name", Function.EQUALS, new Atom<>(details.getGreTunnelName()))); + operations.add(new Select(wifiInetConfigDbTable, conditions)); + + CompletableFuture fResult = ovsdbClient.transact(ovsdbName, operations); + OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + if (((SelectResult) result[0]).getRows().isEmpty()) { + LOG.debug("Adding new Gre Tunnel {}", greTunnelProfile); + + operations.clear(); + operations.add(new Insert(wifiInetConfigDbTable, new Row(tableColumns))); + } else { + LOG.debug("Updating Gre Tunnel {}", greTunnelProfile); + operations.clear(); + operations.add(new Update(wifiInetConfigDbTable, conditions, new Row(tableColumns))); + } + + fResult = ovsdbClient.transact(ovsdbName, operations); + result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); + for (OperationResult res : result) { + LOG.debug("Configure Gre Tunnel Op Result {}", res); + } + } catch (OvsdbClientException | InterruptedException | ExecutionException | TimeoutException e) { + LOG.error("Couldn't configure Gre Tunnel {}", greTunnelProfile, e); + throw new RuntimeException(e); + } + + } + private void createVlanNetworkInterfaces(OvsdbClient ovsdbClient, int vlanId) { try {