X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fswitchmanager%2Fapi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fswitchmanager%2FSwitchConfig.java;h=de18b021ffa0b52919544efbb0e50c655aea56b3;hp=61b2f0a3a8edf0a00a7a783d088b4751e379859a;hb=14ebd2da24a8122c1059e73d80aa1c50afb553dd;hpb=17b979b07eb99462a250a1c9d85ff676330bb4e4 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 61b2f0a3a8..de18b021ff 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,184 @@ package org.opendaylight.controller.switchmanager; import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +import org.opendaylight.controller.configuration.ConfigurationObject; +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 extends ConfigurationObject 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 (!isValidResourceName(nodeId)) { + return new Status(StatusCode.BADREQUEST, "Invalid NodeId"); + } + 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 ("Switch Config [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); + } + }