Couple of changes 21/1321/1
authorAsad Ahmed <asaahmed@cisco.com>
Fri, 20 Sep 2013 23:08:41 +0000 (16:08 -0700)
committerAsad Ahmed <asaahmed@cisco.com>
Fri, 20 Sep 2013 23:12:42 +0000 (16:12 -0700)
1. StaticRoutingImplementation now updates cache after updating nodeconnector for   \
the static route

2. The clone method of MatchField now clones the valid flag and the type

Change-Id: I7e4e274742a4680f1369eecbeff155bbede3283c
Signed-off-by: Asad Ahmed <asaahmed@cisco.com>
opendaylight/forwarding/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/internal/StaticRoutingImplementation.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/MatchField.java

index 89d24192455231487b926ce1b727b9cb76c4c71d..1027f8d170d06048d813d6ecdc3cf12616aac17d 100644 (file)
@@ -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;
@@ -101,11 +100,6 @@ public class StaticRoutingImplementation implements IfNewHostNotify,
         return staticRouteConfigs;
     }
 
-    public void setStaticRouteConfigs(
-            ConcurrentMap<String, StaticRouteConfig> staticRouteConfigs) {
-        this.staticRouteConfigs = staticRouteConfigs;
-    }
-
     @Override
     public Object readObject(ObjectInputStream ois)
             throws FileNotFoundException, IOException, ClassNotFoundException {
@@ -209,10 +203,13 @@ public class StaticRoutingImplementation implements IfNewHostNotify,
     }
 
     private class NotifyStaticRouteWorker implements Callable<Object> {
+
+        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;
         }
@@ -241,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());
@@ -250,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) {
@@ -263,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<String, StaticRoute> 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);
             }
         }
     }
@@ -384,7 +390,7 @@ public class StaticRoutingImplementation implements IfNewHostNotify,
         staticRouteConfigs.put(config.getName(), config);
 
         // Notify
-        checkAndUpdateListeners(sRoute, true);
+        checkAndUpdateListeners(config.getName(), sRoute, true);
         return status;
     }
 
@@ -393,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,
@@ -448,10 +454,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<String, StaticRoute> s : staticRoutes.entrySet()) {
+                    StaticRoute route = s.getValue();
+                    if ((route.getType() == StaticRoute.NextHopType.IPADDRESS)
+                            && route.getHost() == null) {
+                        checkAndUpdateListeners(s.getKey(), route, true);
                     }
                 }
             }
index 54be4c67189412a208dc5cfebb6fef2ff49f0301..b2946d6ab2226157680f4067bab95ffdee78cffa 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.controller.sal.match;
 
 import java.io.Serializable;
+
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
@@ -176,6 +177,8 @@ public class MatchField implements Cloneable, Serializable {
                     cloned.mask = ((byte[]) this.mask).clone();
                 }
             }
+            cloned.type = this.type;
+            cloned.isValid = this.isValid;
         } catch (CloneNotSupportedException e) {
             logger.error("", e);
         }