Improved logging. 02/5902/1
authorShigeru Yasuda <s-yasuda@da.jp.nec.com>
Fri, 4 Apr 2014 08:32:47 +0000 (17:32 +0900)
committerShigeru Yasuda <s-yasuda@da.jp.nec.com>
Fri, 4 Apr 2014 08:32:47 +0000 (17:32 +0900)
  * Don't record FLOW_MOD failure if the target node does not exist.
  * Record inventory change as informational log.

Change-Id: Ic7dab1f2e1b9dcd800ab70c62c15880e5c55f7a2
Signed-off-by: Shigeru Yasuda <s-yasuda@da.jp.nec.com>
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/FlowAddTask.java
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/FlowModTask.java
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/FlowRemoveTask.java
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/VTNFlowDatabase.java
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/VTNManagerImpl.java
manager/implementation/src/test/java/org/opendaylight/vtn/manager/internal/VTNFlowDatabaseTest.java
manager/implementation/src/test/java/org/opendaylight/vtn/manager/internal/VTNManagerImplTest.java

index 9c5d100976180d6e87478a36a0075932925f8aac..d786e243dfbcbac8ac69eec184c04ecdbbc56ecc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 NEC Corporation
+ * Copyright (c) 2013-2014 NEC Corporation
  * All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -27,6 +27,7 @@ import org.opendaylight.controller.forwardingrulesmanager.FlowEntry;
 import org.opendaylight.controller.forwardingrulesmanager.
     IForwardingRulesManager;
 import org.opendaylight.controller.sal.connection.ConnectionLocality;
+import org.opendaylight.controller.sal.core.Node;
 
 /**
  * This class implements flow programming task which installs a VTN flow.
@@ -165,7 +166,8 @@ public class FlowAddTask extends RemoteFlowModTask {
         VTNManagerImpl mgr = getVTNManager();
         IConnectionManager cnm = mgr.getConnectionManager();
         for (FlowEntry fent: entries) {
-            ConnectionLocality cl = cnm.getLocalityStatus(fent.getNode());
+            Node node = fent.getNode();
+            ConnectionLocality cl = cnm.getLocalityStatus(node);
             if (cl == ConnectionLocality.LOCAL) {
                 LocalFlowAddTask task = new LocalFlowAddTask(mgr, fent);
                 local.add(task);
@@ -173,8 +175,15 @@ public class FlowAddTask extends RemoteFlowModTask {
             } else if (cl == ConnectionLocality.NOT_LOCAL) {
                 remote.add(fent);
             } else {
-                LOG.error("{}: Target node of flow entry is disconnected: {}",
-                          mgr.getConnectionManager(), fent);
+                if (mgr.exists(node)) {
+                    LOG.error("{}: " +
+                              "Target node of flow entry is disconnected: {}",
+                              mgr.getContainerName(), fent);
+                } else if (LOG.isTraceEnabled()) {
+                    LOG.trace("{}: Target node does not exist: {}",
+                              mgr.getContainerName(), fent);
+                }
+
                 return false;
             }
         }
@@ -245,16 +254,20 @@ public class FlowAddTask extends RemoteFlowModTask {
 
         // This class expects that the ingress flow is installed to local node.
         IConnectionManager cnm = mgr.getConnectionManager();
-        ConnectionLocality cl = cnm.getLocalityStatus(ingress.getNode());
+        Node node = ingress.getNode();
+        ConnectionLocality cl = cnm.getLocalityStatus(node);
         if (cl != ConnectionLocality.LOCAL) {
             if (cl == ConnectionLocality.NOT_LOCAL) {
                 LOG.error("{}: Ingress flow must be installed to " +
                           "local node: {}", mgr.getContainerName(),
                           ingress);
-            } else {
+            } else if (mgr.exists(node)) {
                 LOG.error("{}: Target node of ingress flow entry is " +
                           "disconnected: {}", mgr.getContainerName(),
                           ingress);
+            } else if (LOG.isTraceEnabled()) {
+                LOG.trace("{}: Target node does not exist: {}",
+                          mgr.getContainerName(), ingress);
             }
             return null;
         }
index d5a5886c9042645bbbaad38d60ba34728b5d102c..0f947182468a4a7617c54f79dcb8bed210b713ac 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 NEC Corporation
+ * Copyright (c) 2013-2014 NEC Corporation
  * All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -19,6 +19,7 @@ import org.opendaylight.vtn.manager.internal.cluster.FlowModResult;
 import org.opendaylight.controller.forwardingrulesmanager.
     IForwardingRulesManager;
 import org.opendaylight.controller.forwardingrulesmanager.FlowEntry;
+import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.utils.Status;
 import org.opendaylight.controller.sal.utils.StatusCode;
 
@@ -180,14 +181,20 @@ public abstract class FlowModTask implements Runnable {
 
         Logger logger = getLogger();
         if (!status.isSuccess()) {
-            if (status.getCode() == StatusCode.UNDEFINED) {
-                logger.error("{}: Failed to install flow entry: Timed Out:" +
-                             "entry={}", vtnManager.getContainerName(),
-                             fent);
-            } else {
-                logger.error("{}: Failed to install flow entry: " +
-                             "status={}, entry={}",
-                             vtnManager.getContainerName(), status, fent);
+            Node node = fent.getNode();
+            if (vtnManager.exists(node)) {
+                if (status.getCode() == StatusCode.UNDEFINED) {
+                    logger.error("{}: Failed to install flow entry: " +
+                                 "Timed Out: entry={}",
+                                 vtnManager.getContainerName(), fent);
+                } else {
+                    logger.error("{}: Failed to install flow entry: " +
+                                 "status={}, entry={}",
+                                 vtnManager.getContainerName(), status, fent);
+                }
+            } else if (logger.isTraceEnabled()) {
+                logger.error("{}: Failed to install flow entry: No node: " +
+                             "entry={}", vtnManager.getContainerName(), fent);
             }
             return false;
         }
@@ -231,14 +238,20 @@ public abstract class FlowModTask implements Runnable {
 
         Logger logger = getLogger();
         if (!status.isSuccess()) {
-            if (status.getCode() == StatusCode.UNDEFINED) {
-                logger.error("{}: Failed to uninstall flow entry: " +
-                             "Timed Out: entry={}",
-                             vtnManager.getContainerName(), status, fent);
-            } else {
-                logger.error("{}: Failed to uninstall flow entry: " +
-                             "status={}, entry={}",
-                             vtnManager.getContainerName(), status, fent);
+            Node node = fent.getNode();
+            if (vtnManager.exists(node)) {
+                if (status.getCode() == StatusCode.UNDEFINED) {
+                    logger.error("{}: Failed to uninstall flow entry: " +
+                                 "Timed Out: entry={}",
+                                 vtnManager.getContainerName(), status, fent);
+                } else {
+                    logger.error("{}: Failed to uninstall flow entry: " +
+                                 "status={}, entry={}",
+                                 vtnManager.getContainerName(), status, fent);
+                }
+            } else if (logger.isTraceEnabled()) {
+                logger.trace("{}: Failed to uninstall flow entry: No node: " +
+                             "entry={}", vtnManager.getContainerName(), fent);
             }
             return false;
         }
index b1c3ac68d745a2c12c4ca98a5e127a1233535c73..9652ef155c9fa9f5dce4f54208cc823951ae4b22 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 NEC Corporation
+ * Copyright (c) 2013-2014 NEC Corporation
  * All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -27,6 +27,7 @@ import org.opendaylight.vtn.manager.internal.cluster.VTNFlow;
 import org.opendaylight.controller.connectionmanager.IConnectionManager;
 import org.opendaylight.controller.forwardingrulesmanager.FlowEntry;
 import org.opendaylight.controller.sal.connection.ConnectionLocality;
+import org.opendaylight.controller.sal.core.Node;
 
 /**
  * This class implements flow programming task which uninstalls VTN flows.
@@ -248,7 +249,8 @@ public class FlowRemoveTask extends RemoteFlowModTask {
         ArrayList<LocalFlowRemoveTask> local =
             new ArrayList<LocalFlowRemoveTask>();
         for (FlowEntry fent: entries) {
-            ConnectionLocality cl = cnm.getLocalityStatus(fent.getNode());
+            Node node = fent.getNode();
+            ConnectionLocality cl = cnm.getLocalityStatus(node);
             if (cl == ConnectionLocality.LOCAL) {
                 LocalFlowRemoveTask task =
                     new LocalFlowRemoveTask(mgr, fent);
@@ -257,8 +259,14 @@ public class FlowRemoveTask extends RemoteFlowModTask {
             } else if (cl == ConnectionLocality.NOT_LOCAL) {
                 remote.add(fent);
             } else {
-                LOG.warn("{}: Target node of flow entry is not connected: {}",
-                         mgr.getConnectionManager(), fent);
+                if (mgr.exists(node)) {
+                    LOG.warn("{}: " +
+                             "Target node of flow entry is not connected: {}",
+                             mgr.getContainerName(), fent);
+                } else if (LOG.isTraceEnabled()) {
+                    LOG.trace("{}: Target node does not exist: {}",
+                              mgr.getContainerName(), fent);
+                }
             }
         }
 
index 2be4ec62633bb60319a25b73570ebce1c0d16ebd..62169331a318c58ab81bca2e606c4922f2b40809 100644 (file)
@@ -76,7 +76,7 @@ public class VTNFlowDatabase {
      *   separating ingress flow from others.
      * </p>
      */
-    protected class FlowCollector {
+    private final class FlowCollector {
         /**
          * List of ingress flow entries.
          */
@@ -112,12 +112,12 @@ public class VTNFlowDatabase {
             }
 
             FlowEntry ingress = it.next();
-            if (match(ingress)) {
+            if (match(mgr, ingress)) {
                 ingressFlows.add(ingress);
             }
             while (it.hasNext()) {
                 FlowEntry fent = it.next();
-                if (match(fent)) {
+                if (match(mgr, fent)) {
                     flowEntries.add(fent);
                 }
             }
@@ -149,43 +149,21 @@ public class VTNFlowDatabase {
         /**
          * Determine whether the given flow entry should be collected or not.
          *
+         * @param mgr   VTN Manager service.
          * @param fent  A flow entry.
          * @return  {@code true} is returned if the given flow entry should
          *          be collected.
          */
-        public boolean match(FlowEntry fent) {
-            // Collect all flow entries.
-            return true;
-        }
-    }
-
-    /**
-     * Flow collector that excludes flow entries in the specified node.
-     */
-    private final class ExcludeNodeCollector extends FlowCollector {
-        /**
-         * A node to be excluded.
-         */
-        private final Node  excludeNode;
-
-        /**
-         * Construct a new collector.
-         *
-         * @param node  A node to be excluded.
-         */
-        private ExcludeNodeCollector(Node node) {
-            excludeNode = node;
-        }
+        private boolean match(VTNManagerImpl mgr, FlowEntry fent) {
+            // Don't collect flow entry in the removed node.
+            Node node = fent.getNode();
+            boolean ret = mgr.exists(node);
+            if (!ret && LOG.isTraceEnabled()) {
+                LOG.trace("{}: Ignore flow entry in the removed node: {}",
+                          mgr.getContainerName(), fent);
+            }
 
-        /**
-         * Determine whether the given flow entry should be handled or not.
-         *
-         * @param fent  A flow entry.
-         * @return  {@code true} is returned if the given flow entry should
-         *          be handled.
-         */
-        public boolean match(FlowEntry fent) {
-            return !excludeNode.equals(fent.getNode());
+            return ret;
         }
     }
 
@@ -297,50 +275,24 @@ public class VTNFlowDatabase {
         }
     }
 
-    /**
-     * Remove all VTN flows related to the given node.
-     *
-     * <p>
-     *   This method assumes that the given node is no longer available.
-     *   So this method never tries to remove flow entries from the given node.
-     * </p>
-     *
-     * @param mgr   VTN Manager service.
-     * @param node  A node associated with a switch.
-     * @return  A {@link FlowRemoveTask} object that will execute the actual
-     *          work is returned. {@code null} is returned if there is no flow
-     *          entry to be removed.
-     */
-    public synchronized FlowRemoveTask removeFlows(VTNManagerImpl mgr,
-                                                   Node node) {
-        return removeFlows(mgr, node, false);
-    }
-
     /**
      * Remove all VTN flows related to the given node.
      *
      * @param mgr        VTN Manager service.
      * @param node       A node associated with a switch.
-     * @param available  Specifying {@code true} means that the given node is
-     *                   still available.
-     *                   Otherwise this method assumes that the given node is
-     *                   no longer available. In this case this method never
-     *                   tries to remove flow entries from the given node.
      * @return  A {@link FlowRemoveTask} object that will execute the actual
      *          work is returned. {@code null} is returned if there is no flow
      *          entry to be removed.
      */
     public synchronized FlowRemoveTask removeFlows(VTNManagerImpl mgr,
-                                                   Node node,
-                                                   boolean available) {
+                                                   Node node) {
         Set<VTNFlow> vflows = nodeFlows.remove(node);
         if (vflows == null) {
             return null;
         }
 
         // Eliminate flow entries in the specified node.
-        FlowCollector collector = (available)
-            ? new FlowCollector() : new ExcludeNodeCollector(node);
+        FlowCollector collector = new FlowCollector();
         for (VTNFlow vflow: vflows) {
             if (LOG.isDebugEnabled()) {
                 LOG.debug("{}:{}: Remove VTN flow related to node {}: " +
index d64ebfcdf6c867800b0f130eb112296502b6ce0d..af54c31f07a89a59b2e8ab462f99b198d6f27ada 100644 (file)
@@ -1154,9 +1154,7 @@ public class VTNManagerImpl
         }
 
         if (nodeDB.putIfAbsent(node, VNodeState.UP) == null) {
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("{}: addNode: New node {}", containerName, node);
-            }
+            LOG.info("{}: addNode: New node {}", containerName, node);
             addDisabledNode(node);
             return true;
         }
@@ -1186,10 +1184,6 @@ public class VTNManagerImpl
      */
     private boolean removeNode(Node node) {
         if (nodeDB.remove(node) != null) {
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("{}: removeNode: Removed {}", containerName, node);
-            }
-
             TimerTask task = disabledNodes.remove(node);
             if (task != null) {
                 task.cancel();
@@ -1200,16 +1194,16 @@ public class VTNManagerImpl
                 new HashSet<NodeConnector>(portDB.keySet());
             for (NodeConnector nc: ports) {
                 if (node.equals(nc.getNode())) {
-                    if (LOG.isDebugEnabled()) {
-                        LOG.debug("{}: removeNode({}): Remove port {}",
-                                  containerName, node, nc);
-                    }
+                    LOG.info("{}: removeNode({}): Remove port {}",
+                             containerName, node, nc);
                     if (portDB.remove(nc) != null) {
                         removeISLPort(nc);
                     }
                 }
             }
 
+            LOG.info("{}: removeNode: Removed {}", containerName, node);
+
             return true;
         }
 
@@ -1280,20 +1274,15 @@ public class VTNManagerImpl
         PortProperty old = portDB.putIfAbsent(nc, pp);
         if (old == null) {
             addNode(nc.getNode(), false);
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("{}: addPort: New port: port={}, prop={}",
-                          containerName, nc, pp);
-            }
+            LOG.info("{}: addPort: New port: port={}, prop={}",
+                     containerName, nc, pp);
             return UpdateType.ADDED;
         }
 
         if (!old.equals(pp)) {
             portDB.put(nc, pp);
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("{}: addPort: Property has been changed: " +
-                          "port={}, prop={} -> {}", containerName, nc,
-                          old, pp);
-            }
+            LOG.info("{}: addPort: Property has been changed: " +
+                     "port={}, prop={} -> {}", containerName, nc, old, pp);
             return UpdateType.CHANGED;
         }
 
@@ -1318,9 +1307,7 @@ public class VTNManagerImpl
      */
     private boolean removePort(NodeConnector nc) {
         if (portDB.remove(nc) != null) {
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("{}: removePort: Removed {}", containerName, nc);
-            }
+            LOG.info("{}: removePort: Removed {}", containerName, nc);
             removeISLPort(nc);
             return true;
         }
@@ -1424,10 +1411,8 @@ public class VTNManagerImpl
      */
     private boolean addISLPort(NodeConnector nc) {
         if (islDB.putIfAbsent(nc, VNodeState.UP) == null) {
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("{}: addISLPort: New ISL port {}",
-                          containerName, nc);
-            }
+            LOG.info("{}: addISLPort: New ISL port {}",
+                     containerName, nc);
             return true;
         }
 
@@ -1453,9 +1438,7 @@ public class VTNManagerImpl
      */
     private boolean removeISLPort(NodeConnector nc) {
         if (islDB.remove(nc) != null) {
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("{}: removeISLPort: Removed {}", containerName, nc);
-            }
+            LOG.info("{}: removeISLPort: Removed {}", containerName, nc);
             return true;
         }
 
@@ -2174,10 +2157,6 @@ public class VTNManagerImpl
     /**
      * Return a set of existing nodes.
      *
-     * <p>
-     *   This method must be called with holding {@link #rwLock}.
-     * </p>
-     *
      * @return  A set of existing nodes.
      */
     public Set<Node> getNodes() {
@@ -2187,10 +2166,6 @@ public class VTNManagerImpl
     /**
      * Determine whether the given node exists or not.
      *
-     * <p>
-     *   This method must be called with holding {@link #rwLock}.
-     * </p>
-     *
      * @param node  Node associated with SDN switch.
      * @return  {@code true} is returned if the given node exists.
      *          Otherwise {@code false} is returned.
@@ -3714,10 +3689,9 @@ public class VTNManagerImpl
         TimerTask task = new TimerTask() {
             @Override
             public void run() {
-                if (disabledNodes.remove(node) != null &&
-                    LOG.isDebugEnabled()) {
-                    LOG.debug("{}: {}: Start packet service",
-                              containerName, node);
+                if (disabledNodes.remove(node) != null) {
+                    LOG.info("{}: {}: Start packet service",
+                             containerName, node);
                 }
             }
         };
@@ -5070,7 +5044,7 @@ public class VTNManagerImpl
                     // all flow entries in this node should be removed by
                     // protocol plugin.
                     for (VTNFlowDatabase fdb: vtnFlowMap.values()) {
-                        fdb.removeFlows(this, node, true);
+                        fdb.removeFlows(this, node);
                     }
                 }
 
index 6ca497daef0523ad68c423369873f051828b96a5..f9ae59119bf5b3e3b994e50457990e93940ed594 100644 (file)
@@ -27,6 +27,7 @@ import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
 import org.opendaylight.controller.sal.utils.NodeCreator;
 import org.opendaylight.vtn.manager.VBridgeIfPath;
 import org.opendaylight.vtn.manager.VBridgePath;
+import org.opendaylight.vtn.manager.VNodeState;
 import org.opendaylight.vtn.manager.VTenantPath;
 import org.opendaylight.vtn.manager.internal.cluster.FlowGroupId;
 import org.opendaylight.vtn.manager.internal.cluster.MacVlan;
@@ -320,6 +321,12 @@ public class VTNFlowDatabaseTest extends TestUseVTNManagerBase {
         Node node0 = NodeCreator.createOFNode(Long.valueOf(0L));
         Node node1 = NodeCreator.createOFNode(Long.valueOf(1L));
         Node node2 = NodeCreator.createOFNode(Long.valueOf(2L));
+
+        // Register nodes to node DB except node2.
+        ConcurrentMap<Node, VNodeState> nodeDB = vtnMgr.getNodeDB();
+        nodeDB.put(node0, VNodeState.UP);
+        nodeDB.put(node1, VNodeState.UP);
+
         Set<Short> portIds0 = new HashSet<Short>(createShorts((short) 10, (short) 5,
                                                               false));
         Set<Short> portIds1 = new HashSet<Short>(createShorts((short) 10, (short) 4,
@@ -371,7 +378,7 @@ public class VTNFlowDatabaseTest extends TestUseVTNManagerBase {
 
         // remove Flows related to node1.
         // flow entries in switch are also removed.
-        FlowRemoveTask task = fdb.removeFlows(vtnMgr, node1, true);
+        FlowRemoveTask task = fdb.removeFlows(vtnMgr, node1);
         assertNotNull(task);
         flushFlowTasks();
 
@@ -422,8 +429,13 @@ public class VTNFlowDatabaseTest extends TestUseVTNManagerBase {
         task = fdb.removeFlows(vtnMgr, node0);
         assertNull(task);
         flushFlowTasks();
-        assertEquals(0, stubObj.getFlowEntries().size());
 
+        // Flow entry in node 2 must be retained.
+        Set<FlowEntry> flows = stubObj.getFlowEntries();
+        assertFalse(flows.isEmpty());
+        for (FlowEntry fent: flows) {
+            assertEquals(node2, fent.getNode());
+        }
     }
 
     /**
@@ -437,6 +449,11 @@ public class VTNFlowDatabaseTest extends TestUseVTNManagerBase {
         Node node0 = NodeCreator.createOFNode(Long.valueOf(0L));
         Node node1 = NodeCreator.createOFNode(Long.valueOf(1L));
         Node node2 = NodeCreator.createOFNode(Long.valueOf(2L));
+        ConcurrentMap<Node, VNodeState> nodeDB = vtnMgr.getNodeDB();
+        nodeDB.put(node0, VNodeState.UP);
+        nodeDB.put(node1, VNodeState.UP);
+        nodeDB.put(node2, VNodeState.UP);
+
         Set<Short> portIds0 = new HashSet<Short>(createShorts((short) 10, (short) 5,
                                                               false));
         Set<Short> portIds1 = new HashSet<Short>(createShorts((short) 10, (short) 4,
index 575dc1fe62c488df7be529518451e81dbbd0d803..d590a0b9c5c2935972c60b3e27196dfeee13c26f 100644 (file)
@@ -3627,6 +3627,9 @@ public class VTNManagerImplTest extends VTNManagerImplTestCommon {
 
         Node node0 = NodeCreator.createOFNode(Long.valueOf(0L));
         Node node1 = NodeCreator.createOFNode(Long.valueOf(1L));
+        ConcurrentMap<Node, VNodeState> nodeDB = vtnMgr.getNodeDB();
+        nodeDB.put(node0, VNodeState.UP);
+        nodeDB.put(node1, VNodeState.UP);
 
         // ingress
         NodeConnector innc
@@ -4125,8 +4128,8 @@ public class VTNManagerImplTest extends VTNManagerImplTestCommon {
         VTNFlowDatabase fdb = vtnMgr.getTenantFlowDB(path.getTenantName());
 
         Node node0 = NodeCreator.createOFNode(Long.valueOf(0L));
-        Set<Node> nodeSet = new HashSet<Node>();
-        nodeSet.add(node0);
+        ConcurrentMap<Node, VNodeState> nodeDB = vtnMgr.getNodeDB();
+        nodeDB.put(node0, VNodeState.UP);
 
         Set<VTNFlow> flows = new HashSet<VTNFlow>();
         VTNFlow flow = fdb.create(vtnMgr);