Enhancement in switch configuration 63/763/3
authorPramila Singh <pramisin@cisco.com>
Thu, 1 Aug 2013 01:57:23 +0000 (18:57 -0700)
committerPramila Singh <pramisin@cisco.com>
Thu, 1 Aug 2013 03:59:38 +0000 (20:59 -0700)
CHANGE:
- Enhance SwitchConfig object to carry any property and not only the three hardcoded fields it has now
- Added removeNodeConfig() and updateNodeConfig() (for adding and modifying) methods to ISwitchConfig
- Deprecated updateSwitchConfig() in favor of updateNodeConfig()
- Deprecated the ISwitchManager.getNodeDescription() in favor of the more extensible existing approach
   of directly requesting the description property
- Bumped switchmanager version number

Change-Id: I000f4b22ec37f9c61fdb5c1ea4e6fdac93811f02
Signed-off-by: Pramila Singh <pramisin@cisco.com>
39 files changed:
opendaylight/arphandler/pom.xml
opendaylight/configuration/integrationtest/pom.xml
opendaylight/configuration/integrationtest/src/test/java/org/opendaylight/controller/configuration/internal/ConfigurationIT.java
opendaylight/forwardingrulesmanager/api/pom.xml
opendaylight/forwardingrulesmanager/implementation/pom.xml
opendaylight/forwardingrulesmanager/integrationtest/pom.xml
opendaylight/hosttracker/api/pom.xml
opendaylight/hosttracker/implementation/pom.xml
opendaylight/hosttracker/integrationtest/pom.xml
opendaylight/hosttracker_new/api/pom.xml
opendaylight/hosttracker_new/implementation/pom.xml
opendaylight/northbound/flowprogrammer/pom.xml
opendaylight/northbound/hosttracker/pom.xml
opendaylight/northbound/integrationtest/pom.xml
opendaylight/northbound/integrationtest/src/test/java/org/opendaylight/controller/northbound/integrationtest/NorthboundIT.java
opendaylight/northbound/subnets/pom.xml
opendaylight/northbound/switchmanager/pom.xml
opendaylight/routing/dijkstra_implementation/pom.xml
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/ForwardingMode.java [new file with mode: 0644]
opendaylight/samples/loadbalancer/pom.xml
opendaylight/samples/simpleforwarding/pom.xml
opendaylight/statisticsmanager/integrationtest/pom.xml
opendaylight/switchmanager/api/pom.xml
opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/ISwitchManager.java
opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/SwitchConfig.java
opendaylight/switchmanager/api/src/test/java/org/opendaylight/controller/switchmanager/SwitchTest.java
opendaylight/switchmanager/implementation/pom.xml
opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.java
opendaylight/switchmanager/integrationtest/pom.xml
opendaylight/usermanager/api/pom.xml
opendaylight/usermanager/implementation/pom.xml
opendaylight/web/devices/pom.xml
opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java
opendaylight/web/flows/pom.xml
opendaylight/web/flows/src/main/java/org/opendaylight/controller/flows/web/Flows.java
opendaylight/web/topology/pom.xml
opendaylight/web/topology/src/main/java/org/opendaylight/controller/topology/web/Topology.java
opendaylight/web/troubleshoot/pom.xml
opendaylight/web/troubleshoot/src/main/java/org/opendaylight/controller/troubleshoot/web/Troubleshoot.java

index 8df1f4c..069ad8d 100644 (file)
@@ -47,7 +47,7 @@
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
-      <version>0.4.0-SNAPSHOT</version>
+      <version>0.5.0-SNAPSHOT</version>
     </dependency>
      <dependency>
       <groupId>org.opendaylight.controller</groupId>
index 037b435..39d08c1 100644 (file)
@@ -60,7 +60,7 @@
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
-      <version>0.4.0-SNAPSHOT</version>
+      <version>0.5.0-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
index 8e1f34e..865c891 100644 (file)
@@ -33,7 +33,7 @@ import org.slf4j.LoggerFactory;
 
 @RunWith(PaxExam.class)
 public class ConfigurationIT {
-    private Logger logger = LoggerFactory
+    private final Logger logger = LoggerFactory
             .getLogger(ConfigurationIT.class);
     // get the OSGI bundle context
     @Inject
@@ -91,7 +91,7 @@ public class ConfigurationIT {
                 mavenBundle("org.opendaylight.controller",
                         "containermanager.implementation", "0.4.0-SNAPSHOT"),
                 mavenBundle("org.opendaylight.controller", "switchmanager",
-                        "0.4.0-SNAPSHOT"),
+                        "0.5.0-SNAPSHOT"),
                 mavenBundle("org.opendaylight.controller",
                         "switchmanager.implementation", "0.4.0-SNAPSHOT"),
                 // needed bundles by configuration
index b2a124b..5b4f0dd 100644 (file)
@@ -79,7 +79,7 @@
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
-      <version>0.4.0-SNAPSHOT</version>
+      <version>0.5.0-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
index df1095c..3519be4 100644 (file)
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
-      <version>0.4.0-SNAPSHOT</version>
+      <version>0.5.0-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
index b626b4f..4e9a374 100644 (file)
@@ -47,7 +47,7 @@
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
-      <version>0.4.0-SNAPSHOT</version>
+      <version>0.5.0-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
index 6da6483..3a35ed0 100644 (file)
@@ -56,7 +56,7 @@
     <dependency>\r
       <groupId>org.opendaylight.controller</groupId>\r
       <artifactId>switchmanager</artifactId>\r
-      <version>0.4.0-SNAPSHOT</version>\r
+      <version>0.5.0-SNAPSHOT</version>\r
     </dependency>\r
     <dependency>\r
       <groupId>org.opendaylight.controller</groupId>\r
index a2ebf1a..5507e46 100644 (file)
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
-      <version>0.4.0-SNAPSHOT</version>
+      <version>0.5.0-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
index a4e5547..0a65f53 100644 (file)
@@ -65,7 +65,7 @@
     <dependency>\r
       <groupId>org.opendaylight.controller</groupId>\r
       <artifactId>switchmanager</artifactId>\r
-      <version>0.4.0-SNAPSHOT</version>\r
+      <version>0.5.0-SNAPSHOT</version>\r
     </dependency>\r
     <dependency>\r
       <groupId>org.opendaylight.controller</groupId>\r
index 6a98c71..c8a8dae 100644 (file)
@@ -56,7 +56,7 @@
     <dependency>\r
       <groupId>org.opendaylight.controller</groupId>\r
       <artifactId>switchmanager</artifactId>\r
-      <version>0.4.0-SNAPSHOT</version>\r
+      <version>0.5.0-SNAPSHOT</version>\r
     </dependency>\r
     <dependency>\r
       <groupId>org.opendaylight.controller</groupId>\r
index 804f5e3..a006c74 100644 (file)
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
-      <version>0.4.0-SNAPSHOT</version>
+      <version>0.5.0-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
index c7e9a77..94991c5 100644 (file)
@@ -69,7 +69,7 @@
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
-      <version>0.4.0-SNAPSHOT</version>
+      <version>0.5.0-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
index f0caa52..40aaf46 100644 (file)
@@ -79,7 +79,7 @@
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
-      <version>0.4.0-SNAPSHOT</version>
+      <version>0.5.0-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
index 90acc8c..5312f8b 100644 (file)
@@ -99,7 +99,7 @@
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
-      <version>0.4.0-SNAPSHOT</version>
+      <version>0.5.0-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
index 66fa52c..4c3fa97 100644 (file)
@@ -58,7 +58,7 @@ import org.slf4j.LoggerFactory;
 
 @RunWith(PaxExam.class)
 public class NorthboundIT {
-    private Logger log = LoggerFactory.getLogger(NorthboundIT.class);
+    private final Logger log = LoggerFactory.getLogger(NorthboundIT.class);
     // get the OSGI bundle context
     @Inject
     private BundleContext bc;
@@ -66,7 +66,7 @@ public class NorthboundIT {
     private IInventoryListener invtoryListener = null;
     private IListenTopoUpdates topoUpdates = null;
 
-    private Boolean debugMsg = false;
+    private final Boolean debugMsg = false;
 
     private String stateToString(int state) {
         switch (state) {
@@ -1271,7 +1271,7 @@ public class NorthboundIT {
                 mavenBundle("org.opendaylight.controller", "security", "0.4.0-SNAPSHOT").noStart(),
                 mavenBundle("org.opendaylight.controller", "sal", "0.5.0-SNAPSHOT"),
                 mavenBundle("org.opendaylight.controller", "sal.implementation", "0.4.0-SNAPSHOT"),
-                mavenBundle("org.opendaylight.controller", "switchmanager", "0.4.0-SNAPSHOT"),
+                mavenBundle("org.opendaylight.controller", "switchmanager", "0.5.0-SNAPSHOT"),
                 mavenBundle("org.opendaylight.controller", "switchmanager.implementation", "0.4.0-SNAPSHOT"),
                 mavenBundle("org.opendaylight.controller", "forwardingrulesmanager", "0.4.0-SNAPSHOT"),
                 mavenBundle("org.opendaylight.controller", "forwardingrulesmanager.implementation", "0.4.0-SNAPSHOT"),
index 977365f..a3931be 100644 (file)
@@ -36,7 +36,7 @@
           <dependency>
             <groupId>org.opendaylight.controller</groupId>
             <artifactId>switchmanager</artifactId>
-            <version>0.4.0-SNAPSHOT</version>
+            <version>0.5.0-SNAPSHOT</version>
           </dependency>
         </dependencies>
       </plugin>
@@ -90,7 +90,7 @@
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
-      <version>0.4.0-SNAPSHOT</version>
+      <version>0.5.0-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller.thirdparty</groupId>
index 26e1b24..556c964 100644 (file)
@@ -75,7 +75,7 @@
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
-      <version>0.4.0-SNAPSHOT</version>
+      <version>0.5.0-SNAPSHOT</version>
     </dependency>
 
     <dependency>
index 22036b5..0e45e06 100644 (file)
@@ -60,7 +60,7 @@
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
-      <version>0.4.0-SNAPSHOT</version>
+      <version>0.5.0-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/ForwardingMode.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/ForwardingMode.java
new file mode 100644 (file)
index 0000000..b83e3a6
--- /dev/null
@@ -0,0 +1,74 @@
+package org.opendaylight.controller.sal.core;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * The class represents the forwarding mode property of a node.
+ */
+@XmlRootElement
+@SuppressWarnings("serial")
+public class ForwardingMode extends Property {
+    @XmlElement
+    private final int modeValue;
+    public static final int REACTIVE_FORWARDING = 0;
+    public static final int PROACTIVE_FORWARDING = 1;
+    public static final String name = "mode";
+
+    /*
+     * Private constructor used for JAXB mapping
+     */
+    private ForwardingMode() {
+        super(name);
+        this.modeValue = REACTIVE_FORWARDING;
+    }
+
+    public ForwardingMode(int mode) {
+        super(name);
+        this.modeValue = mode;
+    }
+
+    public int getValue() {
+        return this.modeValue;
+    }
+
+    public boolean isProactive() {
+        return (modeValue == ForwardingMode.PROACTIVE_FORWARDING);
+    }
+
+    public boolean isValid() {
+        return ((modeValue >= 0) && (modeValue <= 1));
+    }
+
+    @Override
+    public ForwardingMode clone() {
+        return new ForwardingMode(this.modeValue);
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + modeValue;
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (!super.equals(obj))
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        ForwardingMode other = (ForwardingMode) obj;
+        if (modeValue != other.modeValue)
+            return false;
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        return "Mode[" + modeValue + "]";
+    }
+}
\ No newline at end of file
index ca7e93c..0ab5e4b 100644 (file)
@@ -76,7 +76,7 @@
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
-      <version>0.4.0-SNAPSHOT</version>
+      <version>0.5.0-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
index f12331c..2d7c2f2 100644 (file)
@@ -71,7 +71,7 @@
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
-      <version>0.4.0-SNAPSHOT</version>
+      <version>0.5.0-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>junit</groupId>
index f6e84ca..2286263 100644 (file)
@@ -70,7 +70,7 @@
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
-      <version>0.4.0-SNAPSHOT</version>
+      <version>0.5.0-SNAPSHOT</version>
     </dependency>
 
       <dependency>
index 106ff3d..dd3ccfa 100644 (file)
@@ -10,7 +10,7 @@
   </parent>
 
   <artifactId>switchmanager</artifactId>
-  <version>0.4.0-SNAPSHOT</version>
+  <version>0.5.0-SNAPSHOT</version>
   <packaging>bundle</packaging>
 
   <properties>
index 48f5aa4..ee2c2c2 100644 (file)
@@ -19,12 +19,6 @@ import org.opendaylight.controller.sal.core.NodeConnector;
 import org.opendaylight.controller.sal.core.Property;
 import org.opendaylight.controller.sal.utils.Status;
 
-import org.opendaylight.controller.switchmanager.SpanConfig;
-import org.opendaylight.controller.switchmanager.Subnet;
-import org.opendaylight.controller.switchmanager.SubnetConfig;
-import org.opendaylight.controller.switchmanager.Switch;
-import org.opendaylight.controller.switchmanager.SwitchConfig;
-
 /**
  * Primary purpose of this interface is to provide methods for application to
  * access various system resources and inventory data including nodes, node
@@ -129,14 +123,40 @@ public interface ISwitchManager {
      * Update Switch specific configuration such as Switch Name and Tier
      *
      * @param cfgConfig refer to {@link Open Declaration org.opendaylight.controller.switchmanager.SwitchConfig}
+     *
+     * @deprecated replaced by updateNodeConfig(switchConfig)
      */
+    @Deprecated
     public void updateSwitchConfig(SwitchConfig cfgObject);
 
+    /**
+     * Update Node specific configuration such as Node Name and Tier
+     *
+     * @param cfgConfig
+     *            refer to {@link Open Declaration
+     *            org.opendaylight.controller.switchmanager.SwitchConfig}
+     * @return "Success" or failure reason
+     */
+    public Status updateNodeConfig(SwitchConfig switchConfig);
+
+    /**
+     * Removes node properties configured by the user
+     *
+     * @param nodeId
+     *            Node Identifier as specified by
+     *            {@link org.opendaylight.controller.sal.core.Node}
+     * @return "Success" or failure reason
+     */
+    public Status removeNodeConfig(String nodeId);
+
     /**
      * Return the previously configured Switch Configuration given the node id
      *
-     * @param nodeId Node Identifier as specified by {@link org.opendaylight.controller.sal.core.Node}
-     * @return {@link org.opendaylight.controller.switchmanager.SwitchConfig} resources
+     * @param nodeId
+     *            Node Identifier as specified by
+     *            {@link org.opendaylight.controller.sal.core.Node}
+     * @return {@link org.opendaylight.controller.switchmanager.SwitchConfig}
+     *         resources
      */
     public SwitchConfig getSwitchConfig(String nodeId);
 
@@ -357,5 +377,6 @@ public interface ISwitchManager {
      * configured and the network node does not provide its description,
      * an empty string is returned.
      */
+    @Deprecated
     public String getNodeDescription(Node node);
 }
index c595c43..ba9d1a1 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
  *
 package org.opendaylight.controller.switchmanager;
 
 import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.opendaylight.controller.sal.core.Description;
+import org.opendaylight.controller.sal.core.ForwardingMode;
+import org.opendaylight.controller.sal.core.Property;
+import org.opendaylight.controller.sal.core.Tier;
+import org.opendaylight.controller.sal.utils.Status;
+import org.opendaylight.controller.sal.utils.StatusCode;
 
 /**
- * The class describes a switch configuration including node identifier, node
- * name, tier number and proactive/reactive mode.
+ * The class describes a switch configuration
  */
-public class SwitchConfig implements Serializable {
+public class SwitchConfig implements Cloneable, Serializable {
     private static final long serialVersionUID = 1L;
-    String nodeId;
-    String description;
-    String tier;
-    String mode;
+    private final String nodeId;
+    private final Map<String, Property> nodeProperties;
+
+    public SwitchConfig(String nodeId, Map<String, Property> nodeProperties) {
+        this.nodeId = nodeId;
+        this.nodeProperties = (nodeProperties == null) ? new HashMap<String, Property>()
+                : new HashMap<String, Property>(nodeProperties);
+    }
 
+    @Deprecated
     public SwitchConfig(String nodeId, String description, String tier, String mode) {
-        super();
         this.nodeId = nodeId;
-        this.description = description;
-        this.tier = tier;
-        this.mode = mode;
+        this.nodeProperties = new HashMap<String, Property>();
+        Property desc = new Description(description);
+        this.nodeProperties.put(desc.getName(), desc);
+        Property nodeTier = new Tier(Integer.valueOf(tier));
+        this.nodeProperties.put(nodeTier.getName(), nodeTier);
+        Property forwardingMode = new ForwardingMode(Integer.valueOf(mode));
+        this.nodeProperties.put(forwardingMode.getName(), forwardingMode);
     }
 
     public String getNodeId() {
-        return nodeId;
+        return this.nodeId;
+    }
+
+    public Map<String, Property> getNodeProperties() {
+        return new HashMap<String, Property>(this.nodeProperties);
+    }
+
+    public Property getProperty(String PropName) {
+        return nodeProperties.get(PropName);
     }
 
+    /**
+     * This method returns the configured description of the node
+     *
+     * @return Configured description
+     *
+     * @deprecated replaced by getProperty(Description.propertyName)
+     */
+    @Deprecated
     public String getNodeDescription() {
-        return description;
+        Description description = (Description) getProperty(Description.propertyName);
+        return (description == null) ? null : description.getValue();
     }
 
+    /**
+     * This method returns the configured Tier of a node
+     *
+     * @return Configured tier
+     *
+     * @deprecated replaced by getProperty(Tier.TierPropName)
+     */
+    @Deprecated
     public String getTier() {
-        return tier;
+        Tier tier = (Tier) getProperty(Tier.TierPropName);
+        return (tier == null) ? null : String.valueOf(tier.getValue());
     }
 
+    /**
+     * This method returns the configured Forwarding Mode of a node
+     *
+     * @return Configured Forwarding Mode
+     *
+     * @deprecated replaced by getProperty(ForwardingMode.name)
+     */
+    @Deprecated
     public String getMode() {
-        return mode;
+        ForwardingMode forwardingMode = (ForwardingMode) getProperty(ForwardingMode.name);
+        return (forwardingMode == null) ? null : String.valueOf(forwardingMode.getValue());
     }
 
+    /**
+     * This method returns true, if the configured forwarding mode is proactive,
+     * else false
+     *
+     * @return true, if the configured forwarding mode is proactive, else false
+     *
+     * @deprecated replaced by isProactive() API of ForwardingMode property
+     */
+    @Deprecated
     public boolean isProactive() {
-        return Integer.parseInt(mode) != 0;
+        return Integer.parseInt(getMode()) == ForwardingMode.PROACTIVE_FORWARDING;
     }
 
     public static long getSerialversionuid() {
         return serialVersionUID;
     }
 
+    public Status validate() {
+        Status validCheck = validateNodeId();
+        if (validCheck.isSuccess()) {
+            validCheck = validateNodeProperties();
+        }
+        return validCheck;
+    }
+
+    private Status validateNodeId() {
+        if (nodeId == null || nodeId.isEmpty()) {
+            return new Status(StatusCode.BADREQUEST, "NodeId cannot be empty");
+        }
+        return new Status(StatusCode.SUCCESS);
+    }
+
+    private Status validateNodeProperties() {
+        if (nodeProperties == null) {
+            return new Status(StatusCode.BADREQUEST, "nodeProperties cannot be null");
+        }
+        return new Status(StatusCode.SUCCESS);
+    }
+
     @Override
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result
-                + ((description == null) ? 0 : description.hashCode());
-        result = prime * result + ((mode == null) ? 0 : mode.hashCode());
         result = prime * result + ((nodeId == null) ? 0 : nodeId.hashCode());
-        result = prime * result + ((tier == null) ? 0 : tier.hashCode());
+        result = prime * result + ((nodeProperties == null) ? 0 : nodeProperties.hashCode());
         return result;
     }
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj)
+        if (this == obj) {
             return true;
-        if (obj == null)
+        }
+        if (obj == null) {
             return false;
-        if (getClass() != obj.getClass())
+        }
+        if (getClass() != obj.getClass()) {
             return false;
+        }
         SwitchConfig other = (SwitchConfig) obj;
-        if (description == null) {
-            if (other.description != null)
-                return false;
-        } else if (!description.equals(other.description))
-            return false;
-        if (mode == null) {
-            if (other.mode != null)
-                return false;
-        } else if (!mode.equals(other.mode))
-            return false;
         if (nodeId == null) {
-            if (other.nodeId != null)
+            if (other.nodeId != null) {
                 return false;
-        } else if (!nodeId.equals(other.nodeId))
+            }
+        } else if (!nodeId.equals(other.nodeId)) {
             return false;
-        if (tier == null) {
-            if (other.tier != null)
+        }
+        if (nodeProperties == null) {
+            if (other.nodeProperties != null) {
                 return false;
-        } else if (!tier.equals(other.tier))
+            }
+        } else if (!nodeProperties.equals(other.nodeProperties)) {
             return false;
+        }
         return true;
     }
 
     @Override
     public String toString() {
-        return ("SwitchConfig [Node=" + nodeId + ", Description=" + description +
-                ", Tier=" + tier + ", Mode=" + mode + "]");
+        return ("SwitchConfig [Node=" + nodeId + ", Properties=" + nodeProperties + "]");
     }
+
+    /**
+     * Implement clonable interface
+     */
+    @Override
+    public SwitchConfig clone() {
+        Map<String, Property> nodeProperties = (this.nodeProperties == null) ? null : new HashMap<String, Property>(
+                this.nodeProperties);
+        return new SwitchConfig(this.nodeId, nodeProperties);
+    }
+
 }
index 18b3195..2f49895 100644 (file)
@@ -11,15 +11,23 @@ package org.opendaylight.controller.switchmanager;
 import static org.junit.Assert.fail;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Map;
 import java.util.Set;
 
 import org.junit.Assert;
 import org.junit.Test;
+import org.opendaylight.controller.sal.core.Description;
+import org.opendaylight.controller.sal.core.ForwardingMode;
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.controller.sal.core.Property;
+import org.opendaylight.controller.sal.core.Tier;
+import org.opendaylight.controller.sal.utils.GlobalConstants;
 import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
 import org.opendaylight.controller.sal.utils.NodeCreator;
+import org.opendaylight.controller.sal.utils.ServiceHelper;
 
 public class SwitchTest {
 
@@ -122,24 +130,21 @@ public class SwitchTest {
 
     @Test
     public void testSwitchConfig(){
-        SwitchConfig sc = new SwitchConfig(null, null, null, null);
-        SwitchConfig sc2 = new SwitchConfig(null, null, null, null);
-        Assert.assertTrue(sc.equals(sc2));
-
-        Assert.assertNull(sc.getMode());
-        Assert.assertNull(sc.getNodeId());
-        Assert.assertNull(sc.getTier());
-        Assert.assertNull(sc.getNodeDescription());
-
-        SwitchConfig sc3 = new SwitchConfig("123", "name", "tier", "mode");
-        SwitchConfig sc4 = new SwitchConfig("123", "name", "tier", "mode");
-        Assert.assertFalse(sc.equals(sc3));
-        Assert.assertTrue(sc3.equals(sc4));
-
-        Assert.assertTrue(sc3.getNodeId().equals("123"));
-        Assert.assertTrue(sc3.getNodeDescription().equals("name"));
-        Assert.assertTrue(sc3.getTier().equals("tier"));
-        Assert.assertTrue(sc3.getMode().equals("mode"));
+        Map<String, Property> prop = new HashMap<String, Property>();
+        Property desc = new Description("swicth1");
+        prop.put(desc.getName(), desc);
+        Property tier = new Tier(1);
+        prop.put(tier.getName(), tier);
+        SwitchConfig sc1 = new SwitchConfig("123", prop);
+        SwitchConfig sc2 = new SwitchConfig("123", prop);
+        Property mode = new ForwardingMode(1);
+        prop.put(mode.getName(), mode);
+        SwitchConfig sc3 = new SwitchConfig("123", prop);
+        Assert.assertTrue(sc1.equals(sc2));
+        Assert.assertEquals(tier, sc1.getProperty(Tier.TierPropName));
+        Assert.assertFalse(sc1.equals(sc3));
+        Assert.assertTrue(sc1.hashCode() == sc2.hashCode());
+        Assert.assertTrue(sc1.getNodeProperties().equals(sc2.getNodeProperties()));
     }
 
 }
index 511cab1..28bb6f2 100644 (file)
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
-      <version>0.4.0-SNAPSHOT</version>
+      <version>0.5.0-SNAPSHOT</version>
     </dependency>
   </dependencies>
 </project>
index c24c93c..5d10620 100644 (file)
@@ -42,6 +42,7 @@ import org.opendaylight.controller.sal.core.Bandwidth;
 import org.opendaylight.controller.sal.core.Config;
 import org.opendaylight.controller.sal.core.ConstructionException;
 import org.opendaylight.controller.sal.core.Description;
+import org.opendaylight.controller.sal.core.ForwardingMode;
 import org.opendaylight.controller.sal.core.MacAddress;
 import org.opendaylight.controller.sal.core.Name;
 import org.opendaylight.controller.sal.core.Node;
@@ -670,10 +671,7 @@ CommandProvider {
         if (propMapCurr == null) {
             return;
         }
-        Map<String, Property> propMap = new HashMap<String, Property>();
-        for (String s : propMapCurr.keySet()) {
-            propMap.put(s, propMapCurr.get(s).clone());
-        }
+        Map<String, Property> propMap = new HashMap<String, Property>(propMapCurr);
         Property desc = new Description(cfgObject.getNodeDescription());
         propMap.put(desc.getName(), desc);
         Property tier = new Tier(Integer.parseInt(cfgObject.getTier()));
@@ -691,6 +689,120 @@ CommandProvider {
         }
     }
 
+    @Override
+    public Status updateNodeConfig(SwitchConfig switchConfig) {
+        Status status = switchConfig.validate();
+        if (!status.isSuccess()) {
+            return status;
+        }
+
+        Map<String, Property> updateProperties = switchConfig.getNodeProperties();
+        String nodeId = switchConfig.getNodeId();
+        ForwardingMode mode = (ForwardingMode) updateProperties.get(ForwardingMode.name);
+        if (mode != null) {
+            if (isDefaultContainer) {
+                if (!mode.isValid()) {
+                    return new Status(StatusCode.NOTACCEPTABLE, "Invalid Forwarding Mode Value.");
+                }
+            } else {
+                return new Status(StatusCode.NOTACCEPTABLE,
+                        "Forwarding Mode modification is allowed only in default container");
+            }
+        }
+        boolean modeChange = false;
+        SwitchConfig sc = nodeConfigList.get(nodeId);
+        Map<String, Property> prevNodeProperties = new HashMap<String, Property>();
+        if (sc == null) {
+            if ((mode != null) && mode.isProactive()) {
+                modeChange = true;
+            }
+            if (!updateProperties.isEmpty()) {
+                if (nodeConfigList.putIfAbsent(nodeId, switchConfig) != null) {
+                    return new Status(StatusCode.CONFLICT, "Cluster conflict: Unable to update node configuration");
+                }
+            }
+        } else {
+            prevNodeProperties = new HashMap<String, Property>(sc.getNodeProperties());
+            ForwardingMode prevMode = (ForwardingMode) sc.getProperty(ForwardingMode.name);
+            if (mode == null) {
+                if ((prevMode != null) && (prevMode.isProactive())) {
+                    modeChange = true;
+                }
+            } else {
+                if (((prevMode != null) && (prevMode.getValue() != mode.getValue()))
+                        || (prevMode == null && mode.isProactive())) {
+                    modeChange = true;
+                }
+            }
+            if (updateProperties.isEmpty()) {
+                nodeConfigList.remove(nodeId);
+            } else {
+                if (!nodeConfigList.replace(nodeId, sc, switchConfig)) {
+                    return new Status(StatusCode.CONFLICT, "Cluster conflict: Unable to update node configuration");
+                }
+            }
+        }
+        Node node = Node.fromString(nodeId);
+        Map<String, Property> propMapCurr = nodeProps.get(node);
+        Map<String, Property> propMap = new HashMap<String, Property>(propMapCurr);
+        if (propMapCurr == null) {
+            return new Status(StatusCode.SUCCESS);
+        }
+        if (!prevNodeProperties.isEmpty()) {
+            for (String prop : prevNodeProperties.keySet()) {
+                if (!updateProperties.containsKey(prop)) {
+                    if (prop.equals(Description.propertyName)) {
+                        Map<Node, Map<String, Property>> nodeProp = this.inventoryService.getNodeProps();
+                        if (nodeProp.get(node) != null) {
+                            propMap.put(Description.propertyName, nodeProp.get(node).get(Description.propertyName));
+                            continue;
+                        }
+                    }
+                    propMap.remove(prop);
+                }
+            }
+        }
+        propMap.putAll(updateProperties);
+        if (!nodeProps.replace(node, propMapCurr, propMap)) {
+            // TODO rollback using Transactionality
+            return new Status(StatusCode.CONFLICT, "Cluster conflict: Unable to update node configuration.");
+        }
+        if (modeChange) {
+            notifyModeChange(node, (mode == null) ? false : mode.isProactive());
+        }
+        return new Status(StatusCode.SUCCESS);
+    }
+
+    @Override
+    public Status removeNodeConfig(String nodeId) {
+        if ((nodeId == null) || (nodeId.isEmpty())) {
+            return new Status(StatusCode.BADREQUEST, "nodeId cannot be empty.");
+        }
+        Map<String, Property> nodeProperties = getSwitchConfig(nodeId).getNodeProperties();
+        Node node = Node.fromString(nodeId);
+        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()) {
+                if (prop.equals(Description.propertyName)) {
+                    Map<Node, Map<String, Property>> nodeProp = this.inventoryService.getNodeProps();
+                    if (nodeProp.get(node) != null) {
+                        propMap.put(Description.propertyName, nodeProp.get(node).get(Description.propertyName));
+                        continue;
+                    }
+                }
+                propMap.remove(prop);
+            }
+            if (!nodeProps.replace(node, propMapCurr, propMap)) {
+                return new Status(StatusCode.CONFLICT, "Cluster conflict: Unable to update node configuration.");
+            }
+        }
+        if (nodeConfigList != null) {
+            nodeConfigList.remove(nodeId);
+        }
+        return new Status(StatusCode.SUCCESS);
+    }
+
     @Override
     public Status saveSwitchConfig() {
         // Publish the save config event to the cluster nodes
@@ -791,12 +903,8 @@ CommandProvider {
         }
 
         Map<String, Property> propMapCurr = nodeProps.get(node);
-        Map<String, Property> propMap = new HashMap<String, Property>();
-        if (propMapCurr != null) {
-            for (String s : propMapCurr.keySet()) {
-                propMap.put(s, propMapCurr.get(s).clone());
-            }
-        }
+        Map<String, Property> propMap = (propMapCurr == null) ? new HashMap<String, Property>()
+                : new HashMap<String, Property>(propMapCurr);
 
         // copy node properties from plugin
         if (props != null) {
@@ -809,14 +917,13 @@ CommandProvider {
         boolean proactiveForwarding = false;
         if (nodeConfigList != null) {
             String nodeId = node.toString();
-            for (SwitchConfig conf : nodeConfigList.values()) {
-                if (conf.getNodeId().equals(nodeId)) {
-                    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;
+            SwitchConfig conf = nodeConfigList.get(nodeId);
+            if (conf != null && (conf.getNodeProperties() != null)) {
+                Map<String, Property> nodeProperties = conf.getNodeProperties();
+                propMap.putAll(nodeProperties);
+                if (nodeProperties.get(ForwardingMode.name) != null) {
+                    ForwardingMode mode = (ForwardingMode) nodeProperties.get(ForwardingMode.name);
+                    proactiveForwarding = mode.isProactive();
                 }
             }
         }
@@ -831,8 +938,7 @@ CommandProvider {
         }
 
         if (!result) {
-            log.debug(
-                    "Cluster conflict: Conflict while adding the node properties. Node: {}  Properties: {}",
+            log.debug("Cluster conflict: Conflict while adding the node properties. Node: {}  Properties: {}",
                     node.getID(), props);
             addNodeProps(node, propMap);
         }
@@ -871,12 +977,8 @@ CommandProvider {
         }
 
         Map<String, Property> propMapCurr = nodeProps.get(node);
-        Map<String, Property> propMap = new HashMap<String, Property>();
-        if (propMapCurr != null) {
-            for (String s : propMapCurr.keySet()) {
-                propMap.put(s, propMapCurr.get(s).clone());
-            }
-        }
+        Map<String, Property> propMap = (propMapCurr == null) ? new HashMap<String, Property>()
+                : new HashMap<String, Property>(propMapCurr);
 
         // copy node properties from plugin
         for (Property prop : props) {
@@ -1003,11 +1105,7 @@ CommandProvider {
                 return;
             }
 
-            Map<String, Property> propMap = new HashMap<String, Property>();
-            for (String s : propMapCurr.keySet()) {
-                propMap.put(s, propMapCurr.get(s).clone());
-            }
-
+            Map<String, Property> propMap = new HashMap<String, Property>(propMapCurr);
             propMap.put(prop.getName(), prop);
 
             if (nodeProps.replace(node, propMapCurr, propMap)) {
@@ -1029,11 +1127,7 @@ CommandProvider {
                 if (!propMapCurr.containsKey(propName)) {
                     return new Status(StatusCode.SUCCESS);
                 }
-                Map<String, Property> propMap = new HashMap<String, Property>();
-                for (String s : propMapCurr.keySet()) {
-                    propMap.put(s, propMapCurr.get(s).clone());
-                }
-
+                Map<String, Property> propMap = new HashMap<String, Property>(propMapCurr);
                 propMap.remove(propName);
                 if (nodeProps.replace(node, propMapCurr, propMap)) {
                     return new Status(StatusCode.SUCCESS);
@@ -1196,13 +1290,8 @@ CommandProvider {
     public Status addNodeConnectorProp(NodeConnector nodeConnector,
             Property prop) {
         Map<String, Property> propMapCurr = getNodeConnectorProps(nodeConnector);
-        Map<String, Property> propMap = new HashMap<String, Property>();
-
-        if (propMapCurr != null) {
-            for (String s : propMapCurr.keySet()) {
-                propMap.put(s, propMapCurr.get(s).clone());
-            }
-        }
+        Map<String, Property> propMap = (propMapCurr == null) ? new HashMap<String, Property>()
+                : new HashMap<String, Property>(propMapCurr);
 
         String msg = "Cluster conflict: Unable to add NodeConnector Property.";
         // Just add the nodeConnector if prop is not available (in a non-default
@@ -1282,12 +1371,7 @@ CommandProvider {
             return new Status(StatusCode.SUCCESS);
         }
 
-        Map<String, Property> propMap = new HashMap<String, Property>();
-
-        for (String s : propMapCurr.keySet()) {
-            propMap.put(s, propMapCurr.get(s).clone());
-        }
-
+        Map<String, Property> propMap = new HashMap<String, Property>(propMapCurr);
         propMap.remove(propName);
         boolean result = nodeConnectorProps.replace(nodeConnector, propMapCurr, propMap);
         String msg = "Cluster conflict: Unable to remove NodeConnector property.";
@@ -1559,7 +1643,8 @@ CommandProvider {
         for (Node node : getNodes()) {
             SwitchConfig sc = getSwitchConfig(node.toString());
             if ((sc != null) && isDefaultContainer) {
-                service.modeChangeNotify(node, sc.isProactive());
+                ForwardingMode mode = (ForwardingMode) sc.getProperty(ForwardingMode.name);
+                service.modeChangeNotify(node, (mode == null) ? false : mode.isProactive());
             }
         }
     }
@@ -1965,6 +2050,9 @@ CommandProvider {
             } else if (propName.equalsIgnoreCase(Bandwidth.BandwidthPropName)) {
                 long bw = Long.parseLong(propValue);
                 return new Bandwidth(bw);
+            } else if (propName.equalsIgnoreCase(ForwardingMode.name)) {
+                int mode = Integer.parseInt(propValue);
+                return new ForwardingMode(mode);
             } else {
                 log.debug("Not able to create {} property", propName);
             }
index e774dae..af12bbe 100644 (file)
@@ -16,7 +16,7 @@
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
-      <version>0.4.0-SNAPSHOT</version>
+      <version>0.5.0-SNAPSHOT</version>
     </dependency>
       <dependency>
       <groupId>org.opendaylight.controller</groupId>
index 877461d..311465e 100644 (file)
@@ -28,7 +28,6 @@
               org.opendaylight.controller.sal.core,
               org.opendaylight.controller.sal.packet,
               org.opendaylight.controller.sal.utils,
-              org.opendaylight.controller.switchmanager,
               org.opendaylight.controller.containermanager,
               org.slf4j,
               org.eclipse.osgi.framework.console,
     </plugins>
   </build>
   <dependencies>
-    <dependency>
-      <groupId>org.opendaylight.controller</groupId>
-      <artifactId>switchmanager</artifactId>
-      <version>0.4.0-SNAPSHOT</version>
-    </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>containermanager</artifactId>
index a558fa2..0350dc5 100644 (file)
@@ -28,7 +28,6 @@
               org.opendaylight.controller.sal.core,
               org.opendaylight.controller.sal.packet,
               org.opendaylight.controller.sal.utils,
-              org.opendaylight.controller.switchmanager,
               org.opendaylight.controller.containermanager,
               org.slf4j,
               org.eclipse.osgi.framework.console,
       <artifactId>usermanager</artifactId>
       <version>0.4.0-SNAPSHOT</version>
     </dependency>
-    <dependency>
-      <groupId>org.opendaylight.controller</groupId>
-      <artifactId>switchmanager</artifactId>
-      <version>0.4.0-SNAPSHOT</version>
-    </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>containermanager</artifactId>
index eb0b5d3..116640c 100644 (file)
@@ -97,7 +97,7 @@
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
-      <version>0.4.0-SNAPSHOT</version>
+      <version>0.5.0-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
index 34aef8a..e6a785f 100644 (file)
@@ -26,9 +26,12 @@ import org.opendaylight.controller.forwarding.staticrouting.StaticRouteConfig;
 import org.opendaylight.controller.sal.authorization.Privilege;
 import org.opendaylight.controller.sal.authorization.UserLevel;
 import org.opendaylight.controller.sal.core.Config;
+import org.opendaylight.controller.sal.core.Description;
+import org.opendaylight.controller.sal.core.ForwardingMode;
 import org.opendaylight.controller.sal.core.Name;
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.controller.sal.core.Property;
 import org.opendaylight.controller.sal.core.State;
 import org.opendaylight.controller.sal.core.Tier;
 import org.opendaylight.controller.sal.utils.GlobalConstants;
@@ -95,45 +98,39 @@ public class Devices implements IDaylightWeb {
         String userName = request.getUserPrincipal().getName();
         Privilege privilege = DaylightWebUtil.getContainerPrivilege(userName, containerName, this);
 
-        ISwitchManager switchManager = (ISwitchManager) ServiceHelper
-                .getInstance(ISwitchManager.class, containerName, this);
+        ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, containerName,
+                this);
         List<Map<String, String>> nodeData = new ArrayList<Map<String, String>>();
         if (switchManager != null && privilege != Privilege.NONE) {
             for (Switch device : switchManager.getNetworkDevices()) {
                 HashMap<String, String> nodeDatum = new HashMap<String, String>();
                 Node node = device.getNode();
-                Tier tier = (Tier) switchManager.getNodeProp(node,
-                        Tier.TierPropName);
-
+                Tier tier = (Tier) switchManager.getNodeProp(node, Tier.TierPropName);
                 nodeDatum.put("containerName", containerName);
-                nodeDatum.put("nodeName",
-                        switchManager.getNodeDescription(node));
+                Description description = (Description) switchManager.getNodeProp(node, Description.propertyName);
+                String desc = (description == null) ? "" : description.getValue();
+                nodeDatum.put("nodeName", desc);
                 nodeDatum.put("nodeId", node.toString());
-                int tierNumber = (tier == null) ? TierHelper.unknownTierNumber
-                        : tier.getValue();
-                nodeDatum.put("tierName", TierHelper.getTierName(tierNumber)
-                        + " (Tier-" + tierNumber + ")");
+                int tierNumber = (tier == null) ? TierHelper.unknownTierNumber : tier.getValue();
+                nodeDatum.put("tierName", TierHelper.getTierName(tierNumber) + " (Tier-" + tierNumber + ")");
                 nodeDatum.put("tier", tierNumber + "");
-                SwitchConfig sc = switchManager.getSwitchConfig(device
-                        .getNode().toString());
-                String modeStr = (sc != null) ? sc.getMode() : "0";
+                String modeStr = "0";
+                ForwardingMode mode = (ForwardingMode) switchManager.getNodeProp(node, ForwardingMode.name);
+                if (mode != null) {
+                    modeStr = String.valueOf(mode.getValue());
+                }
                 nodeDatum.put("mode", modeStr);
 
                 nodeDatum.put("json", gson.toJson(nodeDatum));
-                nodeDatum.put("mac", HexEncode.bytesToHexString(device
-                        .getDataLayerAddress()));
+                nodeDatum.put("mac", HexEncode.bytesToHexString(device.getDataLayerAddress()));
                 StringBuffer sb1 = new StringBuffer();
-                Set<NodeConnector> nodeConnectorSet = device
-                        .getNodeConnectors();
+                Set<NodeConnector> nodeConnectorSet = device.getNodeConnectors();
                 if (nodeConnectorSet != null && nodeConnectorSet.size() > 0) {
                     Map<Short, String> portList = new HashMap<Short, String>();
                     List<String> intfList = new ArrayList<String>();
                     for (NodeConnector nodeConnector : nodeConnectorSet) {
-                        String nodeConnectorNumberToStr = nodeConnector.getID()
-                                .toString();
-                        Name ncName = ((Name) switchManager
-                                .getNodeConnectorProp(nodeConnector,
-                                        Name.NamePropName));
+                        String nodeConnectorNumberToStr = nodeConnector.getID().toString();
+                        Name ncName = ((Name) switchManager.getNodeConnectorProp(nodeConnector, Name.NamePropName));
                         Config portStatus = ((Config) switchManager
                                 .getNodeConnectorProp(nodeConnector,
                                         Config.ConfigPropName));
@@ -234,11 +231,22 @@ public class Devices implements IDaylightWeb {
         try {
             ISwitchManager switchManager = (ISwitchManager) ServiceHelper
                     .getInstance(ISwitchManager.class, containerName, this);
-            SwitchConfig cfg = new SwitchConfig(nodeId, nodeName, tier,
-                    operationMode);
-            switchManager.updateSwitchConfig(cfg);
-            resultBean.setStatus(true);
-            resultBean.setMessage("Updated node information successfully");
+            Map<String, Property> nodeProperties = new HashMap<String, Property>();
+            Property desc = new Description(nodeName);
+            nodeProperties.put(desc.getName(), desc);
+            Property nodeTier = new Tier(Integer.parseInt(tier));
+            nodeProperties.put(nodeTier.getName(), nodeTier);
+            Property mode = new ForwardingMode(Integer.parseInt(operationMode));
+            nodeProperties.put(mode.getName(), mode);
+            SwitchConfig cfg = new SwitchConfig(nodeId, nodeProperties);
+            Status result = switchManager.updateNodeConfig(cfg);
+            if (!result.isSuccess()) {
+                resultBean.setStatus(false);
+                resultBean.setMessage(result.getDescription());
+            } else {
+                resultBean.setStatus(true);
+                resultBean.setMessage("Updated node information successfully");
+            }
         } catch (Exception e) {
             resultBean.setStatus(false);
             resultBean.setMessage("Error updating node information. "
@@ -737,8 +745,10 @@ public class Devices implements IDaylightWeb {
                 .getInstance(ISwitchManager.class, containerName, this);
         String description = "";
         if (switchManager != null) {
-            description = switchManager.getNodeDescription(Node
-                    .fromString(nodeId));
+            Description desc = (Description) switchManager.getNodeProp(Node.fromString(nodeId), Description.propertyName);
+            if(desc != null) {
+                description = desc.getValue();
+            }
         }
         return (description.isEmpty() || description.equalsIgnoreCase("none")) ? nodeId
                 : description;
index 7aa0ac9..922d4a9 100644 (file)
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
-      <version>0.4.0-SNAPSHOT</version>
+      <version>0.5.0-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
index 145ef90..4396c95 100644 (file)
@@ -20,6 +20,7 @@ import org.opendaylight.controller.forwardingrulesmanager.FlowConfig;
 import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager;
 import org.opendaylight.controller.sal.authorization.Privilege;
 import org.opendaylight.controller.sal.authorization.UserLevel;
+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;
@@ -107,9 +108,7 @@ public class Flows implements IDaylightWeb {
             entry.put("flow", flowConfig);
             entry.put("name", flowConfig.getName());
             Node node = flowConfig.getNode();
-            String description = switchManager.getNodeDescription(node);
-            entry.put("node", (description.isEmpty() || description
-                    .equalsIgnoreCase("none")) ? node.toString() : description);
+            entry.put("node", getNodeDesc(node, switchManager));
             entry.put("nodeId", node.toString());
             flowSet.add(entry);
         }
@@ -160,11 +159,7 @@ public class Flows implements IDaylightWeb {
             entry.put("ports", port);
 
             // add name
-            String description = switchManager.getNodeDescription(node
-                    .getNode());
-            entry.put("name", (description.isEmpty() || description
-                    .equalsIgnoreCase("none")) ? node.getNode().toString()
-                    : description);
+            entry.put("name", getNodeDesc(node.getNode(), switchManager));
 
             // add to the node
             nodes.put(node.getNode().toString(), entry);
@@ -205,8 +200,8 @@ public class Flows implements IDaylightWeb {
             String nodeDesc = node.toString();
             SwitchConfig config = switchManager.getSwitchConfig(node
                     .toString());
-            if (config != null) {
-                nodeDesc = config.getNodeDescription();
+            if ((config != null) && (config.getProperty(Description.propertyName) != null)) {
+                nodeDesc = ((Description) config.getProperty(Description.propertyName)).getValue();
             }
 
             nodes.put(nodeDesc, flows.size());
@@ -284,4 +279,11 @@ public class Flows implements IDaylightWeb {
         return (result.isSuccess()) ? StatusCode.SUCCESS.toString() : result
                 .getDescription();
     }
+
+    private String getNodeDesc(Node node, ISwitchManager switchManager) {
+        Description desc = (Description) switchManager.getNodeProp(node, Description.propertyName);
+        String description = (desc == null) ? "" : desc.getValue();
+        return (description.isEmpty() || description.equalsIgnoreCase("none")) ? node.toString() : description;
+    }
+
 }
index 3dbb324..5932820 100644 (file)
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
-      <version>0.4.0-SNAPSHOT</version>
+      <version>0.5.0-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
index 31d743e..fed81eb 100644 (file)
@@ -27,6 +27,7 @@ import javax.servlet.http.HttpServletRequest;
 import org.opendaylight.controller.configuration.IConfigurationAware;
 import org.opendaylight.controller.sal.authorization.Privilege;
 import org.opendaylight.controller.sal.core.Bandwidth;
+import org.opendaylight.controller.sal.core.Description;
 import org.opendaylight.controller.sal.core.Edge;
 import org.opendaylight.controller.sal.core.Host;
 import org.opendaylight.controller.sal.core.Name;
@@ -176,7 +177,8 @@ public class Topology implements IObjectReader, IConfigurationAware {
 
         for (Map.Entry<Node, Set<Edge>> e : nodeEdges.entrySet()) {
             Node n = e.getKey();
-            String description = switchManager.getNodeDescription(n);
+            String description = getNodeDesc(n, switchManager);
+
             NodeBean node = createNodeBean(description, n);
 
             // skip production node
@@ -280,8 +282,7 @@ public class Topology implements IObjectReader, IConfigurationAware {
 
     private String getNodeConnectorDescription(NodeConnector nodeConnector, ISwitchManager switchManager) {
         Node node = nodeConnector.getNode();
-        String description = switchManager.getNodeDescription(node);
-        String name = this.getDescription(description, node);
+        String name = this.getDescription(getNodeDesc(node, switchManager), node);
         return name;
     }
 
@@ -307,7 +308,7 @@ public class Topology implements IObjectReader, IConfigurationAware {
                     continue;
                 }
 
-                String description = switchManager.getNodeDescription(n);
+                String description = getNodeDesc(n, switchManager);
 
                 if ((stagedNodes.containsKey(n.toString()) && metaCache.get(containerName).containsKey(n.toString())) || newNodes.containsKey(n.toString())) {
                         continue;
@@ -609,4 +610,10 @@ public class Topology implements IObjectReader, IConfigurationAware {
         // Perform the class deserialization locally, from inside the package where the class is defined
         return ois.readObject();
     }
+
+    private String getNodeDesc(Node node, ISwitchManager switchManager) {
+        Description desc = (Description) switchManager.getNodeProp(node, Description.propertyName);
+        return (desc == null) ? "" : desc.getValue();
+    }
+
 }
\ No newline at end of file
index 26001d6..db02937 100644 (file)
@@ -98,7 +98,7 @@
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
-      <version>0.4.0-SNAPSHOT</version>
+      <version>0.5.0-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
index f5fda3d..337d721 100644 (file)
@@ -24,6 +24,7 @@ import org.opendaylight.controller.sal.action.Output;
 import org.opendaylight.controller.sal.action.SetVlanId;
 import org.opendaylight.controller.sal.authorization.Privilege;
 import org.opendaylight.controller.sal.authorization.UserLevel;
+import org.opendaylight.controller.sal.core.Description;
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.core.NodeConnector;
 import org.opendaylight.controller.sal.core.TimeStamp;
@@ -109,7 +110,7 @@ public class Troubleshoot implements IDaylightWeb {
             if (nodeSet != null) {
                 for (Node node : nodeSet) {
                     Map<String, String> device = new HashMap<String, String>();
-                    device.put("nodeName", switchManager.getNodeDescription(node));
+                    device.put("nodeName", getNodeDesc(node, switchManager));
                     device.put("nodeId", node.toString());
                     lines.add(device);
                 }
@@ -139,7 +140,7 @@ public class Troubleshoot implements IDaylightWeb {
             if (nodeSet != null) {
                 for (Node node : nodeSet) {
                     Map<String, String> device = new HashMap<String, String>();
-                    device.put("nodeName", switchManager.getNodeDescription(node));
+                    device.put("nodeName", getNodeDesc(node, switchManager));
                     device.put("nodeId", node.toString());
                     TimeStamp timeStamp = (TimeStamp) switchManager.getNodeProp(
                             node, TimeStamp.TimeStampPropName);
@@ -251,10 +252,9 @@ public class Troubleshoot implements IDaylightWeb {
         Match match = flow.getMatch();
         ISwitchManager switchManager = (ISwitchManager) ServiceHelper
                 .getInstance(ISwitchManager.class, containerName, this);
-        String desc = (switchManager == null)?
-                        "" : switchManager.getNodeDescription(node);
-        desc = (desc.isEmpty() || desc.equalsIgnoreCase("none"))?
-                        node.toString(): desc;
+        String desc = getNodeDesc(node, switchManager);
+        desc = (desc == null || desc.isEmpty() || desc.equalsIgnoreCase("none"))?
+                        node.toString() : desc;
         row.put("nodeName", desc);
         if (match.isPresent(MatchType.IN_PORT)) {
             row.put(MatchType.IN_PORT.id(), ((NodeConnector) flow.getMatch()
@@ -368,4 +368,11 @@ public class Troubleshoot implements IDaylightWeb {
         return row;
     }
 
+    private String getNodeDesc(Node node, ISwitchManager switchManager) {
+        if (switchManager == null) {
+            return null;
+        }
+        Description desc = (Description) switchManager.getNodeProp(node, Description.propertyName);
+        return (desc == null) ? "" : desc.getValue();
+    }
 }