ISSUE: After controller restart, proactive flows are not installed
[controller.git] / opendaylight / switchmanager / src / main / java / org / opendaylight / controller / switchmanager / internal / SwitchManagerImpl.java
index b36d8c12839706de4274101e42d6d44e35690bb4..c4f4b111e3fdc976e93b2b9b01f813d87b2cb09b 100755 (executable)
@@ -41,6 +41,7 @@ import org.opendaylight.controller.clustering.services.IClusterServices;
 import org.opendaylight.controller.configuration.IConfigurationContainerAware;
 import org.opendaylight.controller.sal.core.Bandwidth;
 import org.opendaylight.controller.sal.core.Config;
+import org.opendaylight.controller.sal.core.Description;
 import org.opendaylight.controller.sal.core.Name;
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.core.NodeConnector;
@@ -581,12 +582,14 @@ public class SwitchManagerImpl implements ISwitchManager,
         }
     }
 
+    @Override
     public void updateSwitchConfig(SwitchConfig cfgObject) {
         boolean modeChange = false;
 
         SwitchConfig sc = nodeConfigList.get(cfgObject.getNodeId());
-        if ((sc == null) || !cfgObject.getMode().equals(sc.getMode()))
+        if ((sc == null) || !cfgObject.getMode().equals(sc.getMode())) {
             modeChange = true;
+        }
 
         nodeConfigList.put(cfgObject.getNodeId(), cfgObject);
         try {
@@ -600,8 +603,8 @@ public class SwitchManagerImpl implements ISwitchManager,
                 } else {
                     propMap = new HashMap<String, Property>();
                 }
-                Property name = new Name(cfgObject.getNodeName());
-                propMap.put(name.getName(), name);
+                Property desc = new Description(cfgObject.getNodeDescription());
+                propMap.put(desc.getName(), desc);
                 Property tier = new Tier(Integer.parseInt(cfgObject.getTier()));
                 propMap.put(tier.getName(), tier);
                 addNodeProps(node, propMap);
@@ -610,8 +613,7 @@ public class SwitchManagerImpl implements ISwitchManager,
                         .getMode());
 
                 if (modeChange) {
-                    notifyModeChange(node, (Integer.parseInt(cfgObject
-                            .getMode()) != 0));
+                    notifyModeChange(node, cfgObject.isProactive());
                 }
             }
         } catch (Exception e) {
@@ -714,8 +716,9 @@ public class SwitchManagerImpl implements ISwitchManager,
 
     private void addNode(Node node, Set<Property> props) {
         log.trace("{} added", node);
-        if (nodeProps == null)
+        if (nodeProps == null) {
             return;
+        }
 
         Map<String, Property> propMap;
         if (nodeProps.get(node) != null) {
@@ -732,14 +735,16 @@ public class SwitchManagerImpl implements ISwitchManager,
         }
 
         // copy node properties from config
+        boolean proactiveForwarding = false;
         if (nodeConfigList != null) {
-            String nodeId = node.getNodeIDString();
+            String nodeId = node.toString();
             for (SwitchConfig conf : nodeConfigList.values()) {
                 if (conf.getNodeId().equals(nodeId)) {
-                    Property name = new Name(conf.getNodeName());
-                    propMap.put(name.getName(), name);
+                    Property description = new Description(conf.getNodeDescription());
+                    propMap.put(description.getName(), description);
                     Property tier = new Tier(Integer.parseInt(conf.getTier()));
                     propMap.put(tier.getName(), tier);
+                    proactiveForwarding = conf.isProactive();
                     break;
                 }
             }
@@ -749,8 +754,13 @@ public class SwitchManagerImpl implements ISwitchManager,
         // check if span ports are configed
         addSpanPorts(node);
 
-        /* notify node listeners */
+        // notify node listeners
         notifyNode(node, UpdateType.ADDED, propMap);
+        
+        // notify proactive mode forwarding
+        if (proactiveForwarding) {
+               notifyModeChange(node, true);
+        }
     }
 
     private void removeNode(Node node) {
@@ -816,8 +826,9 @@ public class SwitchManagerImpl implements ISwitchManager,
 
         log.trace("{} {}", nodeConnector, type);
 
-        if (nodeConnectorProps == null)
+        if (nodeConnectorProps == null) {
             return;
+        }
 
         switch (type) {
         case ADDED:
@@ -862,7 +873,7 @@ public class SwitchManagerImpl implements ISwitchManager,
         Set<Node> nodes = getNodes();
         if (nodes != null) {
             for (Node node : nodes) {
-                if (id == (Long) node.getID()) {
+                if (id.equals((Long)node.getID())) {
                     return node;
                 }
             }
@@ -1025,24 +1036,6 @@ public class SwitchManagerImpl implements ISwitchManager,
         return (propMap != null) ? propMap.get(propName) : null;
     }
 
-    @Override
-    public List<Map<String, String>> getListNodeIdNameMap() {
-        List<Map<String, String>> list = new ArrayList<Map<String, String>>();
-        Set<Node> nset = this.nodeProps.keySet();
-        if (nset == null) {
-            return list;
-        }
-        for (Node node : nset) {
-            Map<String, String> map = new HashMap<String, String>(2);
-            Name nodeName = (Name) getNodeProp(node, Name.NamePropName);
-            map.put("nodeId", node.toString());
-            map.put("nodeName", ((nodeName == null) || nodeName.getValue()
-                    .equals("")) ? node.toString() : nodeName.getValue());
-            list.add(map);
-        }
-        return list;
-    }
-
     private byte[] getHardwareMAC() {
         Enumeration<NetworkInterface> nis;
         try {
@@ -1384,8 +1377,7 @@ public class SwitchManagerImpl implements ISwitchManager,
         for (Node node : getNodes()) {
             SwitchConfig sc = getSwitchConfig(node.toString());
             if ((sc != null) && isDefaultContainer) {
-                service.modeChangeNotify(node,
-                        (Integer.parseInt(sc.getMode()) != 0));
+                service.modeChangeNotify(node, sc.isProactive());
             }
         }
     }
@@ -1462,9 +1454,9 @@ public class SwitchManagerImpl implements ISwitchManager,
             return;
         }
         for (Node node : nodeSet) {
-            Name name = ((Name) getNodeProp(node, Name.NamePropName));
+               Description desc = ((Description) getNodeProp(node, Description.propertyName));
             Tier tier = ((Tier) getNodeProp(node, Tier.TierPropName));
-            String nodeName = (name == null) ? "" : name.getValue();
+            String nodeName = (desc == null) ? "" : desc.getValue();
             int tierNum = (tier == null) ? 0 : tier.getValue();
             ci.println(node + "            " + node.getType()
                     + "            " + nodeName + "            " + tierNum);
@@ -1647,10 +1639,10 @@ public class SwitchManagerImpl implements ISwitchManager,
 
     @Override
     public boolean isSpecial(NodeConnector p) {
-        if (p.equals(NodeConnectorIDType.CONTROLLER) ||
-            p.equals(NodeConnectorIDType.ALL) ||
-            p.equals(NodeConnectorIDType.SWSTACK) ||
-            p.equals(NodeConnectorIDType.HWPATH)) {
+        if (p.getType().equals(NodeConnectorIDType.CONTROLLER) ||
+            p.getType().equals(NodeConnectorIDType.ALL) ||
+            p.getType().equals(NodeConnectorIDType.SWSTACK) ||
+            p.getType().equals(NodeConnectorIDType.HWPATH)) {
             return true;
         }
         return false;
@@ -1754,8 +1746,8 @@ public class SwitchManagerImpl implements ISwitchManager,
                }
                
                try {
-                       if (propName.equalsIgnoreCase(Name.NamePropName)) {
-                               return new Name(propValue);
+                       if (propName.equalsIgnoreCase(Description.propertyName)) {
+                               return new Description(propValue);
                        } else if (propName.equalsIgnoreCase(Tier.TierPropName)) {
                                int tier = Integer.parseInt(propValue);
                                return new Tier(tier);
@@ -1771,4 +1763,21 @@ public class SwitchManagerImpl implements ISwitchManager,
 
                return null;
     }
+       
+       @Override
+       public String getNodeDescription(Node node) {
+       // Check first if user configured a name
+        SwitchConfig config = getSwitchConfig(node.getNodeIDString());
+        if (config != null) {
+               String configuredDesc = config.getNodeDescription();
+               if (configuredDesc != null && !configuredDesc.isEmpty()) {
+                       return configuredDesc;
+               }
+        }
+        
+        // No name configured by user, get the node advertised name
+        Description desc = (Description) getNodeProp(node, Description.propertyName);
+        return (desc == null /*|| desc.getValue().equalsIgnoreCase("none")*/) ?        
+                                       "" : desc.getValue();
+    }
 }