Merge "Fix for hosttracker. Ignore ARP messages from internal nodes."
authorGiovanni Meo <gmeo@cisco.com>
Tue, 20 Aug 2013 06:53:55 +0000 (06:53 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 20 Aug 2013 06:53:55 +0000 (06:53 +0000)
opendaylight/forwarding/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/internal/StaticRoutingImplementation.java
opendaylight/forwarding/staticrouting/src/test/java/org/opendaylight/controller/forwarding/staticrouting/StaticRouteTest.java
opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/IForwardingRulesManager.java
opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java
opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java
opendaylight/usermanager/implementation/src/main/java/org/opendaylight/controller/usermanager/internal/UserManagerImpl.java

index ec6da387691f617cefb810c5624e67ddab613770..eac854c10674f796fae64ec174aaef07aad4aed5 100644 (file)
@@ -97,6 +97,7 @@ public class StaticRoutingImplementation implements IfNewHostNotify,
         }
     }
 
+    @Override
     public ConcurrentMap<String, StaticRouteConfig> getStaticRouteConfigs() {
         return staticRouteConfigs;
     }
@@ -258,11 +259,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);
@@ -285,8 +288,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
@@ -322,6 +326,7 @@ public class StaticRoutingImplementation implements IfNewHostNotify,
         return 0;
     }
 
+    @Override
     public StaticRoute getBestMatchStaticRoute(InetAddress ipAddress) {
         ByteBuffer bblongestPrefix = null;
         try {
@@ -349,10 +354,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;
         }
@@ -361,22 +365,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<String, StaticRoute> 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);
@@ -424,8 +435,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
index 4a497a058c0df7a1bdc5b16c5a0cac656010c8f3..25b2dacde10656cba2475775136265d85817fc18 100644 (file)
@@ -83,9 +83,9 @@ public class StaticRouteTest {
         Assert.assertFalse(staticRoute1.equals(staticRoute3));
         Assert.assertFalse(staticRoute1.equals(staticRoute4));
 
-        Assert.assertTrue(staticRoute1.compareTo(staticRoute2) == 0 ? true : false);
-        Assert.assertFalse(staticRoute1.compareTo(staticRoute3) == 0 ? true : false);
-        Assert.assertTrue(staticRoute1.compareTo(staticRoute4) == 0 ? true : false);
+        Assert.assertTrue(staticRoute1.compareTo(staticRoute2) == 0);
+        Assert.assertFalse(staticRoute1.compareTo(staticRoute3) == 0);
+        Assert.assertTrue(staticRoute1.compareTo(staticRoute4) == 0);
 
         }
 
index 4b8257488ef08c072785a5cef76f56c550ba882a..9f0005e7fb5b2aa3a7dea5cbfa62fdf11be94dab 100644 (file)
@@ -199,14 +199,29 @@ public interface IForwardingRulesManager {
 
     /**
      * Returns the list of Flow entries across network nodes which are part of
-     * the same flow group, policy
+     * the same flow group, policy. This list contains the flows as they were
+     * requested to be installed by the applications, before any merging with
+     * container flow is done.
      *
      * @param group
      *            the group name
-     * @return the list of flow entries belonging to the specified group
+     * @return the original list of flow entries belonging to the specified group
      */
     public List<FlowEntry> getFlowEntriesForGroup(String group);
 
+    /**
+     * Returns the list of Flow entries installed in network nodes which are part of
+     * the same flow group, policy. This list contains the effective flows installed
+     * on the nodes after the merging with any possible container flow was performed.
+     * If no container flow are specified, this method returns the same list returned
+     * by getFlowEntriesForGroup(String group).
+     *
+     * @param group
+     *            the group name
+     * @return the list of container flow merged flow entries belonging to the specified group
+     */
+    public List<FlowEntry> getInstalledFlowEntriesForGroup(String policyName);
+
     /**
      * Add a list of output port to the flow with the specified name on the
      * specified network node
index e7a8a8e22cf9b2c4826d33bcd2450253f7d59794..57f3e8eb3605195f516aec818ee6c4200fec9186 100644 (file)
@@ -1034,6 +1034,19 @@ public class ForwardingRulesManager implements IForwardingRulesManager, PortGrou
         return list;
     }
 
+    @Override
+    public List<FlowEntry> getInstalledFlowEntriesForGroup(String policyName) {
+        List<FlowEntry> list = new ArrayList<FlowEntry>();
+        if (policyName != null && !policyName.trim().isEmpty()) {
+            for (Map.Entry<FlowEntryInstall, FlowEntryInstall> entry : this.installedSwView.entrySet()) {
+                if (policyName.equals(entry.getKey().getGroupName())) {
+                    list.add(entry.getKey().getInstall().clone());
+                }
+            }
+        }
+        return list;
+    }
+
     @Override
     public void addOutputPort(Node node, String flowName, List<NodeConnector> portList) {
 
index 835f40e6c6663e1f2a04f9c99922def15defabec..78c78f55429980466e42d5074e07e133c9cfa0bb 100644 (file)
@@ -712,7 +712,8 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
                 switchConfig = new SwitchConfig(nodeId, updateProperties);
             } else {
                 // check if description is configured or was published by any other node
-                for (Node n : nodeProps.keySet()) {
+                for (Map.Entry<Node, Map<String, Property>> entry : nodeProps.entrySet()) {
+                    Node n = entry.getKey();
                     Description desc = (Description) getNodeProp(n, Description.propertyName);
                     NodeDescription nDesc = (this.statisticsManager == null) ? null : this.statisticsManager
                             .getNodeDescription(n);
@@ -762,7 +763,8 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
             return new Status(StatusCode.SUCCESS);
         }
         Map<String, Property> propMap = new HashMap<String, Property>(propMapCurr);
-        for (String prop : prevNodeProperties.keySet()) {
+        for (Map.Entry<String, Property> entry : prevNodeProperties.entrySet()) {
+            String prop = entry.getKey();
             if (!updateProperties.containsKey(prop)) {
                 if (prop.equals(Description.propertyName)) {
                     if (!advertisedDesc.isEmpty()) {
@@ -795,7 +797,8 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
         Map<String, Property> propMapCurr = nodeProps.get(node);
         if ((propMapCurr != null) && (nodeProperties != null) && (!nodeProperties.isEmpty())) {
             Map<String, Property> propMap = new HashMap<String, Property>(propMapCurr);
-            for (String prop : nodeProperties.keySet()) {
+            for (Map.Entry<String, Property> entry : nodeProperties.entrySet()) {
+                String prop = entry.getKey();
                 if (prop.equals(Description.propertyName)) {
                     Map<Node, Map<String, Property>> nodeProp = this.inventoryService.getNodeProps();
                     if (nodeProp.get(node) != null) {
@@ -955,6 +958,17 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
             return;
         }
         nodeProps.remove(node);
+        nodeConnectorNames.remove(node);
+        Set<NodeConnector> removeNodeConnectorSet = new HashSet<NodeConnector>();
+        for (Map.Entry<NodeConnector, Map<String, Property>> entry : nodeConnectorProps.entrySet()) {
+            NodeConnector nodeConnector = entry.getKey();
+            if (nodeConnector.getNode().equals(node)) {
+                removeNodeConnectorSet.add(nodeConnector);
+            }
+        }
+        for (NodeConnector nc : removeNodeConnectorSet) {
+            nodeConnectorProps.remove(nc);
+        }
 
         // check if span ports need to be cleaned up
         removeSpanPorts(node);
@@ -1161,7 +1175,8 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
         }
 
         Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
-        for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
+        for (Map.Entry<NodeConnector, Map<String, Property>> entry : nodeConnectorProps.entrySet()) {
+            NodeConnector nodeConnector = entry.getKey();
             if (!nodeConnector.getNode().equals(node)) {
                 continue;
             }
@@ -1180,7 +1195,8 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
         }
 
         Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
-        for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
+        for (Map.Entry<NodeConnector, Map<String, Property>> entry : nodeConnectorProps.entrySet()) {
+            NodeConnector nodeConnector = entry.getKey();
             if (!nodeConnector.getNode().equals(node)) {
                 continue;
             }
@@ -1197,7 +1213,8 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
         }
 
         Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
-        for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
+        for (Map.Entry<NodeConnector, Map<String, Property>> entry : nodeConnectorProps.entrySet()) {
+            NodeConnector nodeConnector = entry.getKey();
             if (!nodeConnector.getNode().equals(node)
                     || isSpecial(nodeConnector)) {
                 continue;
@@ -1336,9 +1353,10 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
                 Map<String, NodeConnector> mapCurr = nodeConnectorNames.get(node);
                 Map<String, NodeConnector> map = new HashMap<String, NodeConnector>();
                 if (mapCurr != null) {
-                    for (String s : mapCurr.keySet()) {
+                    for (Map.Entry<String, NodeConnector> entry : mapCurr.entrySet()) {
+                        String s = entry.getKey();
                         try {
-                            map.put(s, new NodeConnector(mapCurr.get(s)));
+                            map.put(s, new NodeConnector(entry.getValue()));
                         } catch (ConstructionException e) {
                             e.printStackTrace();
                         }
@@ -1397,9 +1415,10 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
                     Map<String, NodeConnector> mapCurr = nodeConnectorNames.get(node);
                     if (mapCurr != null) {
                         Map<String, NodeConnector> map = new HashMap<String, NodeConnector>();
-                        for (String s : mapCurr.keySet()) {
+                        for (Map.Entry<String, NodeConnector> entry : mapCurr.entrySet()) {
+                            String s = entry.getKey();
                             try {
-                                map.put(s, new NodeConnector(mapCurr.get(s)));
+                                map.put(s, new NodeConnector(entry.getValue()));
                             } catch (ConstructionException e) {
                                 e.printStackTrace();
                             }
@@ -1433,9 +1452,10 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
                 Map<String, NodeConnector> mapCurr = nodeConnectorNames.get(node);
                 if (mapCurr != null) {
                     Map<String, NodeConnector> map = new HashMap<String, NodeConnector>();
-                    for (String s : mapCurr.keySet()) {
+                    for (Map.Entry<String, NodeConnector> entry : mapCurr.entrySet()) {
+                        String s = entry.getKey();
                         try {
-                            map.put(s, new NodeConnector(mapCurr.get(s)));
+                            map.put(s, new NodeConnector(entry.getValue()));
                         } catch (ConstructionException e) {
                             e.printStackTrace();
                         }
@@ -1682,7 +1702,8 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
             service.notifyNode(node, type, propMap);
         }
 
-        for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
+        for (Map.Entry<NodeConnector, Map<String, Property>> entry : nodeConnectorProps.entrySet()) {
+            NodeConnector nodeConnector = entry.getKey();
             propMap = nodeConnectorProps.get(nodeConnector);
             service.notifyNodeConnector(nodeConnector, type, propMap);
         }
index add453f09fb895268fb3a409d591d5ecb28110c8..fedc432f207d6514cc040ebdb527d5530cf679da 100644 (file)
@@ -446,7 +446,7 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
         }
 
         for (UserConfig conf : confList.values()) {
-            addLocalUser(conf);
+            addRemoveLocalUserInternal(conf, false);
         }
     }
 
@@ -483,21 +483,44 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
     /*
      * Interaction with GUI START
      */
-    public Status addRemoveLocalUser(UserConfig AAAconf, boolean delete) {
+    private Status addRemoveLocalUser(UserConfig AAAconf, boolean delete) {
         // UserConfig Validation check
         Status validCheck = AAAconf.validate();
         if (!validCheck.isSuccess()) {
             return validCheck;
         }
 
+        String user = AAAconf.getUser();
+
+        // Check default admin user
+        if (user.equals(UserManagerImpl.defaultAdmin)) {
+            String msg = "Invalid Request: Default Network Admin  User cannot be " + ((delete)? "removed" : "added");
+            logger.debug(msg);
+            return new Status(StatusCode.NOTALLOWED, msg);
+        }
+
+        // Check user presence/conflict
+        StatusCode statusCode = null;
+        String reason = null;
+        if (delete && !localUserConfigList.containsKey(user)) {
+            reason = "not found";
+            statusCode = StatusCode.NOTFOUND;
+        } else if (!delete && localUserConfigList.containsKey(user)) {
+            reason = "already present";
+            statusCode = StatusCode.CONFLICT;
+        }
+        if (statusCode != null) {
+            String msg = String.format("User %s %s in configuration database", user, reason);
+            logger.debug(msg);
+            return new Status(statusCode, msg);
+        }
+
+        return addRemoveLocalUserInternal(AAAconf, delete);
+    }
+
+    private Status addRemoveLocalUserInternal(UserConfig AAAconf, boolean delete) {
         // Update Config database
         if (delete) {
-            if (AAAconf.getUser().equals(UserManagerImpl.defaultAdmin)) {
-                String msg = "Invalid Request: Default Network Admin  User "
-                        + "cannot be deleted";
-                logger.debug(msg);
-                return new Status(StatusCode.NOTALLOWED, msg);
-            }
             localUserConfigList.remove(AAAconf.getUser());
             /*
              * A user account has been removed form local database, we assume
@@ -506,16 +529,10 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
              */
             removeUserFromActiveList(AAAconf.getUser());
         } else {
-            if (AAAconf.getUser().equals(UserManagerImpl.defaultAdmin)) {
-                String msg = "Invalid Request: Default Network Admin  User "
-                        + "cannot be added";
-                logger.debug(msg);
-                return new Status(StatusCode.NOTALLOWED, msg);
-            }
             localUserConfigList.put(AAAconf.getUser(), AAAconf);
         }
 
-        return new Status(StatusCode.SUCCESS, null);
+        return new Status(StatusCode.SUCCESS);
     }
 
     private Status addRemoveAAAServer(ServerConfig AAAconf, boolean delete) {
@@ -533,7 +550,7 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
             remoteServerConfigList.put(AAAconf.getAddress(), AAAconf);
         }
 
-        return new Status(StatusCode.SUCCESS, null);
+        return new Status(StatusCode.SUCCESS);
     }
 
     private Status addRemoveAuthInfo(AuthorizationConfig AAAconf, boolean delete) {
@@ -552,7 +569,7 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
             authorizationConfList.put(AAAconf.getUser(), AAAconf);
         }
 
-        return new Status(StatusCode.SUCCESS, null);
+        return new Status(StatusCode.SUCCESS);
     }
 
     @Override
@@ -570,9 +587,11 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
         if (userName == null || userName.trim().isEmpty()) {
             return new Status(StatusCode.BADREQUEST, "Invalid user name");
         }
+
         if (!localUserConfigList.containsKey(userName)) {
             return new Status(StatusCode.NOTFOUND, "User does not exist");
         }
+
         return addRemoveLocalUser(localUserConfigList.get(userName), true);
     }
 
@@ -950,11 +969,10 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
         }
 
         if (success) {
-            return new Status(StatusCode.SUCCESS, null);
+            return new Status(StatusCode.SUCCESS);
         }
 
-        return new Status(StatusCode.INTERNALERROR,
-                "Failed to save user configurations");
+        return new Status(StatusCode.INTERNALERROR, "Failed to save user configurations");
     }
 
     @Override