2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.switchmanager;
11 import java.io.Serializable;
12 import java.util.HashMap;
15 import org.opendaylight.controller.sal.core.Description;
16 import org.opendaylight.controller.sal.core.ForwardingMode;
17 import org.opendaylight.controller.sal.core.Property;
18 import org.opendaylight.controller.sal.core.Tier;
19 import org.opendaylight.controller.sal.utils.Status;
20 import org.opendaylight.controller.sal.utils.StatusCode;
23 * The class describes a switch configuration
25 public class SwitchConfig implements Cloneable, Serializable {
26 private static final long serialVersionUID = 1L;
27 private final String nodeId;
28 private final Map<String, Property> nodeProperties;
30 public SwitchConfig(String nodeId, Map<String, Property> nodeProperties) {
32 this.nodeProperties = (nodeProperties == null) ? new HashMap<String, Property>()
33 : new HashMap<String, Property>(nodeProperties);
37 public SwitchConfig(String nodeId, String description, String tier, String mode) {
39 this.nodeProperties = new HashMap<String, Property>();
40 Property desc = new Description(description);
41 this.nodeProperties.put(desc.getName(), desc);
42 Property nodeTier = new Tier(Integer.valueOf(tier));
43 this.nodeProperties.put(nodeTier.getName(), nodeTier);
44 Property forwardingMode = new ForwardingMode(Integer.valueOf(mode));
45 this.nodeProperties.put(forwardingMode.getName(), forwardingMode);
48 public String getNodeId() {
52 public Map<String, Property> getNodeProperties() {
53 return new HashMap<String, Property>(this.nodeProperties);
56 public Property getProperty(String PropName) {
57 return nodeProperties.get(PropName);
61 * This method returns the configured description of the node
63 * @return Configured description
65 * @deprecated replaced by getProperty(Description.propertyName)
68 public String getNodeDescription() {
69 Description description = (Description) getProperty(Description.propertyName);
70 return (description == null) ? null : description.getValue();
74 * This method returns the configured Tier of a node
76 * @return Configured tier
78 * @deprecated replaced by getProperty(Tier.TierPropName)
81 public String getTier() {
82 Tier tier = (Tier) getProperty(Tier.TierPropName);
83 return (tier == null) ? null : String.valueOf(tier.getValue());
87 * This method returns the configured Forwarding Mode of a node
89 * @return Configured Forwarding Mode
91 * @deprecated replaced by getProperty(ForwardingMode.name)
94 public String getMode() {
95 ForwardingMode forwardingMode = (ForwardingMode) getProperty(ForwardingMode.name);
96 return (forwardingMode == null) ? null : String.valueOf(forwardingMode.getValue());
100 * This method returns true, if the configured forwarding mode is proactive,
103 * @return true, if the configured forwarding mode is proactive, else false
105 * @deprecated replaced by isProactive() API of ForwardingMode property
108 public boolean isProactive() {
109 return Integer.parseInt(getMode()) == ForwardingMode.PROACTIVE_FORWARDING;
112 public static long getSerialversionuid() {
113 return serialVersionUID;
116 public Status validate() {
117 Status validCheck = validateNodeId();
118 if (validCheck.isSuccess()) {
119 validCheck = validateNodeProperties();
124 private Status validateNodeId() {
125 if (nodeId == null || nodeId.isEmpty()) {
126 return new Status(StatusCode.BADREQUEST, "NodeId cannot be empty");
128 return new Status(StatusCode.SUCCESS);
131 private Status validateNodeProperties() {
132 if (nodeProperties == null) {
133 return new Status(StatusCode.BADREQUEST, "nodeProperties cannot be null");
135 return new Status(StatusCode.SUCCESS);
139 public int hashCode() {
140 final int prime = 31;
142 result = prime * result + ((nodeId == null) ? 0 : nodeId.hashCode());
143 result = prime * result + ((nodeProperties == null) ? 0 : nodeProperties.hashCode());
148 public boolean equals(Object obj) {
155 if (getClass() != obj.getClass()) {
158 SwitchConfig other = (SwitchConfig) obj;
159 if (nodeId == null) {
160 if (other.nodeId != null) {
163 } else if (!nodeId.equals(other.nodeId)) {
166 if (nodeProperties == null) {
167 if (other.nodeProperties != null) {
170 } else if (!nodeProperties.equals(other.nodeProperties)) {
177 public String toString() {
178 return ("SwitchConfig [Node=" + nodeId + ", Properties=" + nodeProperties + "]");
182 * Implement clonable interface
185 public SwitchConfig clone() {
186 Map<String, Property> nodeProperties = (this.nodeProperties == null) ? null : new HashMap<String, Property>(
187 this.nodeProperties);
188 return new SwitchConfig(this.nodeId, nodeProperties);