From: Pramila Singh Date: Thu, 1 Aug 2013 01:57:23 +0000 (-0700) Subject: Enhancement in switch configuration X-Git-Tag: releasepom-0.1.0~243^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=fab5707429f1232b70ad1046a2c7abd854e74f72 Enhancement in switch configuration 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 --- diff --git a/opendaylight/arphandler/pom.xml b/opendaylight/arphandler/pom.xml index 8df1f4cffa..069ad8d4a3 100644 --- a/opendaylight/arphandler/pom.xml +++ b/opendaylight/arphandler/pom.xml @@ -47,7 +47,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/configuration/integrationtest/pom.xml b/opendaylight/configuration/integrationtest/pom.xml index 037b43515a..39d08c1e3b 100644 --- a/opendaylight/configuration/integrationtest/pom.xml +++ b/opendaylight/configuration/integrationtest/pom.xml @@ -60,7 +60,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/configuration/integrationtest/src/test/java/org/opendaylight/controller/configuration/internal/ConfigurationIT.java b/opendaylight/configuration/integrationtest/src/test/java/org/opendaylight/controller/configuration/internal/ConfigurationIT.java index 8e1f34e612..865c891b6f 100644 --- a/opendaylight/configuration/integrationtest/src/test/java/org/opendaylight/controller/configuration/internal/ConfigurationIT.java +++ b/opendaylight/configuration/integrationtest/src/test/java/org/opendaylight/controller/configuration/internal/ConfigurationIT.java @@ -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 diff --git a/opendaylight/forwardingrulesmanager/api/pom.xml b/opendaylight/forwardingrulesmanager/api/pom.xml index b2a124bb4e..5b4f0dd35a 100644 --- a/opendaylight/forwardingrulesmanager/api/pom.xml +++ b/opendaylight/forwardingrulesmanager/api/pom.xml @@ -79,7 +79,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/forwardingrulesmanager/implementation/pom.xml b/opendaylight/forwardingrulesmanager/implementation/pom.xml index df1095c76d..3519be452a 100644 --- a/opendaylight/forwardingrulesmanager/implementation/pom.xml +++ b/opendaylight/forwardingrulesmanager/implementation/pom.xml @@ -121,7 +121,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/forwardingrulesmanager/integrationtest/pom.xml b/opendaylight/forwardingrulesmanager/integrationtest/pom.xml index b626b4fdaf..4e9a374c4f 100644 --- a/opendaylight/forwardingrulesmanager/integrationtest/pom.xml +++ b/opendaylight/forwardingrulesmanager/integrationtest/pom.xml @@ -47,7 +47,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/hosttracker/api/pom.xml b/opendaylight/hosttracker/api/pom.xml index 6da648324c..3a35ed06ee 100644 --- a/opendaylight/hosttracker/api/pom.xml +++ b/opendaylight/hosttracker/api/pom.xml @@ -56,7 +56,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/hosttracker/implementation/pom.xml b/opendaylight/hosttracker/implementation/pom.xml index a2ebf1aa9d..5507e46035 100644 --- a/opendaylight/hosttracker/implementation/pom.xml +++ b/opendaylight/hosttracker/implementation/pom.xml @@ -103,7 +103,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/hosttracker/integrationtest/pom.xml b/opendaylight/hosttracker/integrationtest/pom.xml index a4e5547059..0a65f53b38 100644 --- a/opendaylight/hosttracker/integrationtest/pom.xml +++ b/opendaylight/hosttracker/integrationtest/pom.xml @@ -65,7 +65,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/hosttracker_new/api/pom.xml b/opendaylight/hosttracker_new/api/pom.xml index 6a98c71e6a..c8a8dae167 100644 --- a/opendaylight/hosttracker_new/api/pom.xml +++ b/opendaylight/hosttracker_new/api/pom.xml @@ -56,7 +56,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/hosttracker_new/implementation/pom.xml b/opendaylight/hosttracker_new/implementation/pom.xml index 804f5e3638..a006c74ae1 100644 --- a/opendaylight/hosttracker_new/implementation/pom.xml +++ b/opendaylight/hosttracker_new/implementation/pom.xml @@ -104,7 +104,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/northbound/flowprogrammer/pom.xml b/opendaylight/northbound/flowprogrammer/pom.xml index c7e9a771c1..94991c573e 100644 --- a/opendaylight/northbound/flowprogrammer/pom.xml +++ b/opendaylight/northbound/flowprogrammer/pom.xml @@ -69,7 +69,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/northbound/hosttracker/pom.xml b/opendaylight/northbound/hosttracker/pom.xml index f0caa52d63..40aaf462ad 100644 --- a/opendaylight/northbound/hosttracker/pom.xml +++ b/opendaylight/northbound/hosttracker/pom.xml @@ -79,7 +79,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/northbound/integrationtest/pom.xml b/opendaylight/northbound/integrationtest/pom.xml index 90acc8c59f..5312f8b91f 100644 --- a/opendaylight/northbound/integrationtest/pom.xml +++ b/opendaylight/northbound/integrationtest/pom.xml @@ -99,7 +99,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/northbound/integrationtest/src/test/java/org/opendaylight/controller/northbound/integrationtest/NorthboundIT.java b/opendaylight/northbound/integrationtest/src/test/java/org/opendaylight/controller/northbound/integrationtest/NorthboundIT.java index 66fa52c5ab..4c3fa97864 100644 --- a/opendaylight/northbound/integrationtest/src/test/java/org/opendaylight/controller/northbound/integrationtest/NorthboundIT.java +++ b/opendaylight/northbound/integrationtest/src/test/java/org/opendaylight/controller/northbound/integrationtest/NorthboundIT.java @@ -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"), diff --git a/opendaylight/northbound/subnets/pom.xml b/opendaylight/northbound/subnets/pom.xml index 977365f021..a3931beadd 100644 --- a/opendaylight/northbound/subnets/pom.xml +++ b/opendaylight/northbound/subnets/pom.xml @@ -36,7 +36,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT @@ -90,7 +90,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller.thirdparty diff --git a/opendaylight/northbound/switchmanager/pom.xml b/opendaylight/northbound/switchmanager/pom.xml index 26e1b2469c..556c964055 100644 --- a/opendaylight/northbound/switchmanager/pom.xml +++ b/opendaylight/northbound/switchmanager/pom.xml @@ -75,7 +75,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT diff --git a/opendaylight/routing/dijkstra_implementation/pom.xml b/opendaylight/routing/dijkstra_implementation/pom.xml index 22036b5d64..0e45e06cdf 100644 --- a/opendaylight/routing/dijkstra_implementation/pom.xml +++ b/opendaylight/routing/dijkstra_implementation/pom.xml @@ -60,7 +60,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller 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 index 0000000000..b83e3a696d --- /dev/null +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/ForwardingMode.java @@ -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 diff --git a/opendaylight/samples/loadbalancer/pom.xml b/opendaylight/samples/loadbalancer/pom.xml index ca7e93c5a9..0ab5e4bc99 100644 --- a/opendaylight/samples/loadbalancer/pom.xml +++ b/opendaylight/samples/loadbalancer/pom.xml @@ -76,7 +76,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/samples/simpleforwarding/pom.xml b/opendaylight/samples/simpleforwarding/pom.xml index f12331cbb2..2d7c2f22ec 100644 --- a/opendaylight/samples/simpleforwarding/pom.xml +++ b/opendaylight/samples/simpleforwarding/pom.xml @@ -71,7 +71,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT junit diff --git a/opendaylight/statisticsmanager/integrationtest/pom.xml b/opendaylight/statisticsmanager/integrationtest/pom.xml index f6e84ca78b..228626383e 100644 --- a/opendaylight/statisticsmanager/integrationtest/pom.xml +++ b/opendaylight/statisticsmanager/integrationtest/pom.xml @@ -70,7 +70,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT diff --git a/opendaylight/switchmanager/api/pom.xml b/opendaylight/switchmanager/api/pom.xml index 106ff3dd2a..dd3ccfa5c4 100644 --- a/opendaylight/switchmanager/api/pom.xml +++ b/opendaylight/switchmanager/api/pom.xml @@ -10,7 +10,7 @@ switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT bundle diff --git a/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/ISwitchManager.java b/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/ISwitchManager.java index 48f5aa48f6..ee2c2c2039 100644 --- a/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/ISwitchManager.java +++ b/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/ISwitchManager.java @@ -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); } diff --git a/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/SwitchConfig.java b/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/SwitchConfig.java index c595c43e5b..ba9d1a12f3 100644 --- a/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/SwitchConfig.java +++ b/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/SwitchConfig.java @@ -1,4 +1,3 @@ - /* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * @@ -10,97 +9,183 @@ 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 nodeProperties; + + public SwitchConfig(String nodeId, Map nodeProperties) { + this.nodeId = nodeId; + this.nodeProperties = (nodeProperties == null) ? new HashMap() + : new HashMap(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(); + 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 getNodeProperties() { + return new HashMap(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 nodeProperties = (this.nodeProperties == null) ? null : new HashMap( + this.nodeProperties); + return new SwitchConfig(this.nodeId, nodeProperties); + } + } diff --git a/opendaylight/switchmanager/api/src/test/java/org/opendaylight/controller/switchmanager/SwitchTest.java b/opendaylight/switchmanager/api/src/test/java/org/opendaylight/controller/switchmanager/SwitchTest.java index 18b3195372..2f4989577b 100644 --- a/opendaylight/switchmanager/api/src/test/java/org/opendaylight/controller/switchmanager/SwitchTest.java +++ b/opendaylight/switchmanager/api/src/test/java/org/opendaylight/controller/switchmanager/SwitchTest.java @@ -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 prop = new HashMap(); + 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())); } } diff --git a/opendaylight/switchmanager/implementation/pom.xml b/opendaylight/switchmanager/implementation/pom.xml index 511cab14cd..28bb6f274c 100644 --- a/opendaylight/switchmanager/implementation/pom.xml +++ b/opendaylight/switchmanager/implementation/pom.xml @@ -106,7 +106,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT diff --git a/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.java b/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.java index c24c93c65d..5d10620c44 100644 --- a/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.java +++ b/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.java @@ -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 propMap = new HashMap(); - for (String s : propMapCurr.keySet()) { - propMap.put(s, propMapCurr.get(s).clone()); - } + Map propMap = new HashMap(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 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 prevNodeProperties = new HashMap(); + 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(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 propMapCurr = nodeProps.get(node); + Map propMap = new HashMap(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> 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 nodeProperties = getSwitchConfig(nodeId).getNodeProperties(); + Node node = Node.fromString(nodeId); + Map propMapCurr = nodeProps.get(node); + if ((propMapCurr != null) && (nodeProperties != null) && (!nodeProperties.isEmpty())) { + Map propMap = new HashMap(propMapCurr); + for (String prop : nodeProperties.keySet()) { + if (prop.equals(Description.propertyName)) { + Map> 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 propMapCurr = nodeProps.get(node); - Map propMap = new HashMap(); - if (propMapCurr != null) { - for (String s : propMapCurr.keySet()) { - propMap.put(s, propMapCurr.get(s).clone()); - } - } + Map propMap = (propMapCurr == null) ? new HashMap() + : new HashMap(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 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 propMapCurr = nodeProps.get(node); - Map propMap = new HashMap(); - if (propMapCurr != null) { - for (String s : propMapCurr.keySet()) { - propMap.put(s, propMapCurr.get(s).clone()); - } - } + Map propMap = (propMapCurr == null) ? new HashMap() + : new HashMap(propMapCurr); // copy node properties from plugin for (Property prop : props) { @@ -1003,11 +1105,7 @@ CommandProvider { return; } - Map propMap = new HashMap(); - for (String s : propMapCurr.keySet()) { - propMap.put(s, propMapCurr.get(s).clone()); - } - + Map propMap = new HashMap(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 propMap = new HashMap(); - for (String s : propMapCurr.keySet()) { - propMap.put(s, propMapCurr.get(s).clone()); - } - + Map propMap = new HashMap(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 propMapCurr = getNodeConnectorProps(nodeConnector); - Map propMap = new HashMap(); - - if (propMapCurr != null) { - for (String s : propMapCurr.keySet()) { - propMap.put(s, propMapCurr.get(s).clone()); - } - } + Map propMap = (propMapCurr == null) ? new HashMap() + : new HashMap(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 propMap = new HashMap(); - - for (String s : propMapCurr.keySet()) { - propMap.put(s, propMapCurr.get(s).clone()); - } - + Map propMap = new HashMap(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); } diff --git a/opendaylight/switchmanager/integrationtest/pom.xml b/opendaylight/switchmanager/integrationtest/pom.xml index e774dae115..af12bbee51 100644 --- a/opendaylight/switchmanager/integrationtest/pom.xml +++ b/opendaylight/switchmanager/integrationtest/pom.xml @@ -16,7 +16,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/usermanager/api/pom.xml b/opendaylight/usermanager/api/pom.xml index 877461daaa..311465e3ab 100644 --- a/opendaylight/usermanager/api/pom.xml +++ b/opendaylight/usermanager/api/pom.xml @@ -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, @@ -64,11 +63,6 @@ - - org.opendaylight.controller - switchmanager - 0.4.0-SNAPSHOT - org.opendaylight.controller containermanager diff --git a/opendaylight/usermanager/implementation/pom.xml b/opendaylight/usermanager/implementation/pom.xml index a558fa2048..0350dc5b63 100644 --- a/opendaylight/usermanager/implementation/pom.xml +++ b/opendaylight/usermanager/implementation/pom.xml @@ -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, @@ -68,11 +67,6 @@ usermanager 0.4.0-SNAPSHOT - - org.opendaylight.controller - switchmanager - 0.4.0-SNAPSHOT - org.opendaylight.controller containermanager diff --git a/opendaylight/web/devices/pom.xml b/opendaylight/web/devices/pom.xml index eb0b5d393e..116640cd3d 100644 --- a/opendaylight/web/devices/pom.xml +++ b/opendaylight/web/devices/pom.xml @@ -97,7 +97,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java b/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java index 34aef8af9f..e6a785f586 100644 --- a/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java +++ b/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java @@ -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> nodeData = new ArrayList>(); if (switchManager != null && privilege != Privilege.NONE) { for (Switch device : switchManager.getNetworkDevices()) { HashMap nodeDatum = new HashMap(); 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 nodeConnectorSet = device - .getNodeConnectors(); + Set nodeConnectorSet = device.getNodeConnectors(); if (nodeConnectorSet != null && nodeConnectorSet.size() > 0) { Map portList = new HashMap(); List intfList = new ArrayList(); 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 nodeProperties = new HashMap(); + 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; diff --git a/opendaylight/web/flows/pom.xml b/opendaylight/web/flows/pom.xml index 7aa0ac9454..922d4a9a52 100644 --- a/opendaylight/web/flows/pom.xml +++ b/opendaylight/web/flows/pom.xml @@ -101,7 +101,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/web/flows/src/main/java/org/opendaylight/controller/flows/web/Flows.java b/opendaylight/web/flows/src/main/java/org/opendaylight/controller/flows/web/Flows.java index 145ef9086e..4396c957bf 100644 --- a/opendaylight/web/flows/src/main/java/org/opendaylight/controller/flows/web/Flows.java +++ b/opendaylight/web/flows/src/main/java/org/opendaylight/controller/flows/web/Flows.java @@ -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; + } + } diff --git a/opendaylight/web/topology/pom.xml b/opendaylight/web/topology/pom.xml index 3dbb324988..593282068d 100644 --- a/opendaylight/web/topology/pom.xml +++ b/opendaylight/web/topology/pom.xml @@ -105,7 +105,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/web/topology/src/main/java/org/opendaylight/controller/topology/web/Topology.java b/opendaylight/web/topology/src/main/java/org/opendaylight/controller/topology/web/Topology.java index 31d743ee23..fed81eb2ae 100644 --- a/opendaylight/web/topology/src/main/java/org/opendaylight/controller/topology/web/Topology.java +++ b/opendaylight/web/topology/src/main/java/org/opendaylight/controller/topology/web/Topology.java @@ -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> 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 diff --git a/opendaylight/web/troubleshoot/pom.xml b/opendaylight/web/troubleshoot/pom.xml index 26001d60ab..db02937a00 100644 --- a/opendaylight/web/troubleshoot/pom.xml +++ b/opendaylight/web/troubleshoot/pom.xml @@ -98,7 +98,7 @@ org.opendaylight.controller switchmanager - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/web/troubleshoot/src/main/java/org/opendaylight/controller/troubleshoot/web/Troubleshoot.java b/opendaylight/web/troubleshoot/src/main/java/org/opendaylight/controller/troubleshoot/web/Troubleshoot.java index f5fda3d1bc..337d721696 100644 --- a/opendaylight/web/troubleshoot/src/main/java/org/opendaylight/controller/troubleshoot/web/Troubleshoot.java +++ b/opendaylight/web/troubleshoot/src/main/java/org/opendaylight/controller/troubleshoot/web/Troubleshoot.java @@ -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 device = new HashMap(); - 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 device = new HashMap(); - 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(); + } }