X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fforwarding%2Fstaticrouting%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fforwarding%2Fstaticrouting%2Finternal%2FStaticRoutingImplementation.java;h=315543514e4156e17af453237f001271b6cb4e33;hb=091edbab9bee93cd5d7eda8c1493bdb0e8f8d242;hp=1b2128957e9352ffd93a0a0991abf91ec3a354ea;hpb=f4c0ebfa7997a336d8458b1d8ce4d9d2eeae7599;p=controller.git 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 1b2128957e..315543514e 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 @@ -16,7 +16,6 @@ import java.net.Inet4Address; import java.net.InetAddress; import java.nio.ByteBuffer; import java.util.Collections; -import java.util.Date; import java.util.Dictionary; import java.util.EnumSet; import java.util.HashSet; @@ -63,7 +62,6 @@ public class StaticRoutingImplementation implements IfNewHostNotify, 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; @@ -102,11 +100,6 @@ public class StaticRoutingImplementation implements IfNewHostNotify, return staticRouteConfigs; } - public void setStaticRouteConfigs( - ConcurrentMap staticRouteConfigs) { - this.staticRouteConfigs = staticRouteConfigs; - } - @Override public Object readObject(ObjectInputStream ois) throws FileNotFoundException, IOException, ClassNotFoundException { @@ -210,10 +203,13 @@ public class StaticRoutingImplementation implements IfNewHostNotify, } private class NotifyStaticRouteWorker implements Callable { + + private String name; private StaticRoute staticRoute; private boolean added; - public NotifyStaticRouteWorker(StaticRoute s, boolean update) { + public NotifyStaticRouteWorker(String name, StaticRoute s, boolean update) { + this.name = name; this.staticRoute = s; this.added = update; } @@ -242,6 +238,10 @@ public class StaticRoutingImplementation implements IfNewHostNotify, if (host != null) { log.debug("Next hop {} is found", nh.getHostAddress()); staticRoute.setHost(host); + // static route object has changed + // put the changed object back in the cache + // for it to sync + staticRoutes.put(name, staticRoute); notifyStaticRouteUpdate(staticRoute, added); } else { log.debug("Next hop {} is still not present, try again later", nh.getHostAddress()); @@ -251,8 +251,8 @@ public class StaticRoutingImplementation implements IfNewHostNotify, } } - private void checkAndUpdateListeners(StaticRoute staticRoute, boolean added) { - NotifyStaticRouteWorker worker = new NotifyStaticRouteWorker(staticRoute, added); + private void checkAndUpdateListeners(String name, StaticRoute staticRoute, boolean added) { + NotifyStaticRouteWorker worker = new NotifyStaticRouteWorker(name, staticRoute, added); try { executor.submit(worker); } catch (Exception e) { @@ -264,17 +264,22 @@ public class StaticRoutingImplementation implements IfNewHostNotify, if (host == null) { return; } - for (StaticRoute s : staticRoutes.values()) { - if (s.getType() == StaticRoute.NextHopType.SWITCHPORT) { + for (Map.Entry s : staticRoutes.entrySet()) { + StaticRoute route = s.getValue(); + if (route.getType() == StaticRoute.NextHopType.SWITCHPORT) { continue; } - if (s.getNextHopAddress().equals(host.getNetworkAddress())) { + if (route.getNextHopAddress().equals(host.getNetworkAddress())) { if (added) { - s.setHost(host); + route.setHost(host); } else { - s.setHost(null); + route.setHost(null); } - notifyStaticRouteUpdate(s, added); + // static route object has changed + // put the changed object back in the cache + // for it to sync + staticRoutes.put(s.getKey(), route); + notifyStaticRouteUpdate(route, added); } } } @@ -385,7 +390,7 @@ public class StaticRoutingImplementation implements IfNewHostNotify, staticRouteConfigs.put(config.getName(), config); // Notify - checkAndUpdateListeners(sRoute, true); + checkAndUpdateListeners(config.getName(), sRoute, true); return status; } @@ -394,7 +399,7 @@ public class StaticRoutingImplementation implements IfNewHostNotify, staticRouteConfigs.remove(name); StaticRoute sRoute = staticRoutes.remove(name); if (sRoute != null) { - checkAndUpdateListeners(sRoute, false); + checkAndUpdateListeners(name, sRoute, false); return new Status(StatusCode.SUCCESS, null); } return new Status(StatusCode.NOTFOUND, @@ -433,7 +438,6 @@ public class StaticRoutingImplementation implements IfNewHostNotify, log.debug("forwarding.staticrouting starting on container {}", containerName); - //staticRoutes = new ConcurrentHashMap(); allocateCaches(); retrieveCaches(); this.executor = Executors.newFixedThreadPool(1); @@ -449,10 +453,11 @@ public class StaticRoutingImplementation implements IfNewHostNotify, gatewayProbeTimer.schedule(new TimerTask() { @Override public void run() { - for (StaticRoute s : staticRoutes.values()) { - if ((s.getType() == StaticRoute.NextHopType.IPADDRESS) - && s.getHost() == null) { - checkAndUpdateListeners(s, true); + for (Map.Entry s : staticRoutes.entrySet()) { + StaticRoute route = s.getValue(); + if ((route.getType() == StaticRoute.NextHopType.IPADDRESS) + && route.getHost() == null) { + checkAndUpdateListeners(s.getKey(), route, true); } } }