X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fforwarding%2Fstaticrouting%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fforwarding%2Fstaticrouting%2Finternal%2FStaticRoutingImplementation.java;h=89d24192455231487b926ce1b727b9cb76c4c71d;hp=bccdea416208ef27d30294b9f7ddcebf83a77ba2;hb=4e421e1d66e547633907b8e428945524d45956d5;hpb=8d3fef27e61757b37333f619d5a02c02230a9b6d diff --git a/opendaylight/forwarding/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/internal/StaticRoutingImplementation.java b/opendaylight/forwarding/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/internal/StaticRoutingImplementation.java index bccdea4162..89d2419245 100644 --- a/opendaylight/forwarding/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/internal/StaticRoutingImplementation.java +++ b/opendaylight/forwarding/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/internal/StaticRoutingImplementation.java @@ -36,7 +36,6 @@ import java.util.regex.Pattern; import org.apache.felix.dm.Component; import org.opendaylight.controller.clustering.services.CacheConfigException; import org.opendaylight.controller.clustering.services.CacheExistException; -import org.opendaylight.controller.clustering.services.ICacheUpdateAware; import org.opendaylight.controller.clustering.services.IClusterContainerServices; import org.opendaylight.controller.clustering.services.IClusterServices; import org.opendaylight.controller.configuration.IConfigurationContainerAware; @@ -60,18 +59,15 @@ import org.slf4j.LoggerFactory; * Static Routing feature provides the bridge between SDN and Non-SDN networks. */ public class StaticRoutingImplementation implements IfNewHostNotify, - IForwardingStaticRouting, IObjectReader, IConfigurationContainerAware, - ICacheUpdateAware { + IForwardingStaticRouting, IObjectReader, IConfigurationContainerAware { private static Logger log = LoggerFactory .getLogger(StaticRoutingImplementation.class); private static String ROOT = GlobalConstants.STARTUPHOME.toString(); - private static final String SAVE = "Save"; ConcurrentMap staticRoutes; ConcurrentMap staticRouteConfigs; private IfIptoHost hostTracker; private Timer gatewayProbeTimer; private String staticRoutesFileName = null; - private Map configSaveEvent; private IClusterContainerServices clusterContainerService = null; private Set staticRoutingAware = Collections .synchronizedSet(new HashSet()); @@ -100,6 +96,7 @@ public class StaticRoutingImplementation implements IfNewHostNotify, } } + @Override public ConcurrentMap getStaticRouteConfigs() { return staticRouteConfigs; } @@ -134,8 +131,6 @@ public class StaticRoutingImplementation implements IfNewHostNotify, private Status saveConfig() { - // Publish the save config event to the cluster nodes - configSaveEvent.put(new Date().getTime(), SAVE); return saveConfigInternal(); } @@ -165,14 +160,10 @@ public class StaticRoutingImplementation implements IfNewHostNotify, try { clusterContainerService.createCache( "forwarding.staticrouting.routes", EnumSet - .of(IClusterServices.cacheMode.NON_TRANSACTIONAL)); + .of(IClusterServices.cacheMode.TRANSACTIONAL)); clusterContainerService.createCache( "forwarding.staticrouting.configs", EnumSet - .of(IClusterServices.cacheMode.NON_TRANSACTIONAL)); - clusterContainerService.createCache( - "forwarding.staticrouting.configSaveEvent", EnumSet - .of(IClusterServices.cacheMode.NON_TRANSACTIONAL)); - + .of(IClusterServices.cacheMode.TRANSACTIONAL)); } catch (CacheExistException cee) { log .error("\nCache already exists - destroy and recreate if needed"); @@ -200,25 +191,6 @@ public class StaticRoutingImplementation implements IfNewHostNotify, if (staticRouteConfigs == null) { log.error("\nFailed to get rulesDB handle"); } - configSaveEvent = (ConcurrentMap) clusterContainerService - .getCache("forwarding.staticrouting.configSaveEvent"); - if (configSaveEvent == null) { - log.error("\nFailed to get cache for configSaveEvent"); - } - } - - @Override - public void entryCreated(Long key, String cacheName, boolean local) { - } - - @Override - public void entryUpdated(Long key, String new_value, String cacheName, - boolean originLocal) { - saveConfigInternal(); - } - - @Override - public void entryDeleted(Long key, String cacheName, boolean originLocal) { } private void notifyStaticRouteUpdate(StaticRoute s, boolean update) { @@ -259,6 +231,8 @@ public class StaticRoutingImplementation implements IfNewHostNotify, if (future != null) { try { host = future.get(); + } catch (InterruptedException ioe) { + log.trace("Thread interrupted {}", ioe); } catch (Exception e) { log.error("", e); } @@ -286,11 +260,13 @@ public class StaticRoutingImplementation implements IfNewHostNotify, } private void notifyHostUpdate(HostNodeConnector host, boolean added) { - if (host == null) + if (host == null) { return; + } for (StaticRoute s : staticRoutes.values()) { - if (s.getType() == StaticRoute.NextHopType.SWITCHPORT) + if (s.getType() == StaticRoute.NextHopType.SWITCHPORT) { continue; + } if (s.getNextHopAddress().equals(host.getNetworkAddress())) { if (added) { s.setHost(host); @@ -313,8 +289,9 @@ public class StaticRoutingImplementation implements IfNewHostNotify, } public boolean isIPv4AddressValid(String cidr) { - if (cidr == null) + if (cidr == null) { return false; + } String values[] = cidr.split("/"); Pattern ipv4Pattern = Pattern @@ -350,6 +327,7 @@ public class StaticRoutingImplementation implements IfNewHostNotify, return 0; } + @Override public StaticRoute getBestMatchStaticRoute(InetAddress ipAddress) { ByteBuffer bblongestPrefix = null; try { @@ -377,10 +355,9 @@ public class StaticRoutingImplementation implements IfNewHostNotify, return longestPrefixRoute; } + @Override public Status addStaticRoute(StaticRouteConfig config) { - Status status; - - status = config.isValid(); + Status status = config.isValid(); if (!status.isSuccess()) { return status; } @@ -389,22 +366,29 @@ public class StaticRoutingImplementation implements IfNewHostNotify, "A valid Static Route configuration with this name " + "already exists. Please use a different name"); } - for (StaticRouteConfig s : staticRouteConfigs.values()) { - if (s.equals(config)) { + + // Update database + StaticRoute sRoute = new StaticRoute(config); + + for (Map.Entry entry : staticRoutes.entrySet()) { + if (entry.getValue().compareTo(sRoute) == 0) { return new Status(StatusCode.CONFLICT, - "This conflicts with an existing Static Route " + - "Configuration. Please check the configuration " + - "and try again"); + "This conflicts with an existing Static Route " + + "Configuration. Please check the configuration " + + "and try again"); } } + staticRoutes.put(config.getName(), sRoute); + // Update config databse staticRouteConfigs.put(config.getName(), config); - StaticRoute sRoute = new StaticRoute(config); - staticRoutes.put(config.getName(), sRoute); + + // Notify checkAndUpdateListeners(sRoute, true); return status; } + @Override public Status removeStaticRoute(String name) { staticRouteConfigs.remove(name); StaticRoute sRoute = staticRoutes.remove(name); @@ -452,8 +436,9 @@ public class StaticRoutingImplementation implements IfNewHostNotify, allocateCaches(); retrieveCaches(); this.executor = Executors.newFixedThreadPool(1); - if (staticRouteConfigs.isEmpty()) + if (staticRouteConfigs.isEmpty()) { loadConfiguration(); + } /* * Slow probe to identify any gateway that might have silently appeared