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.configuration.ConfigurationObject;
16 import org.opendaylight.controller.sal.core.Description;
17 import org.opendaylight.controller.sal.core.ForwardingMode;
18 import org.opendaylight.controller.sal.core.Property;
19 import org.opendaylight.controller.sal.core.Tier;
20 import org.opendaylight.controller.sal.utils.Status;
21 import org.opendaylight.controller.sal.utils.StatusCode;
24 * The class describes a switch configuration
26 public class SwitchConfig extends ConfigurationObject implements Cloneable, Serializable {
27 private static final long serialVersionUID = 1L;
28 private final String nodeId;
29 private final Map<String, Property> nodeProperties;
31 public SwitchConfig(String nodeId, Map<String, Property> nodeProperties) {
33 this.nodeProperties = (nodeProperties == null) ? new HashMap<String, Property>()
34 : new HashMap<String, Property>(nodeProperties);
38 public SwitchConfig(String nodeId, String description, String tier, String mode) {
40 this.nodeProperties = new HashMap<String, Property>();
41 Property desc = new Description(description);
42 this.nodeProperties.put(desc.getName(), desc);
43 Property nodeTier = new Tier(Integer.valueOf(tier));
44 this.nodeProperties.put(nodeTier.getName(), nodeTier);
45 Property forwardingMode = new ForwardingMode(Integer.valueOf(mode));
46 this.nodeProperties.put(forwardingMode.getName(), forwardingMode);
49 public String getNodeId() {
53 public Map<String, Property> getNodeProperties() {
54 return new HashMap<String, Property>(this.nodeProperties);
57 public Property getProperty(String PropName) {
58 return nodeProperties.get(PropName);
62 * This method returns the configured description of the node
64 * @return Configured description
66 * @deprecated replaced by getProperty(Description.propertyName)
69 public String getNodeDescription() {
70 Description description = (Description) getProperty(Description.propertyName);
71 return (description == null) ? null : description.getValue();
75 * This method returns the configured Tier of a node
77 * @return Configured tier
79 * @deprecated replaced by getProperty(Tier.TierPropName)
82 public String getTier() {
83 Tier tier = (Tier) getProperty(Tier.TierPropName);
84 return (tier == null) ? null : String.valueOf(tier.getValue());
88 * This method returns the configured Forwarding Mode of a node
90 * @return Configured Forwarding Mode
92 * @deprecated replaced by getProperty(ForwardingMode.name)
95 public String getMode() {
96 ForwardingMode forwardingMode = (ForwardingMode) getProperty(ForwardingMode.name);
97 return (forwardingMode == null) ? null : String.valueOf(forwardingMode.getValue());
101 * This method returns true, if the configured forwarding mode is proactive,
104 * @return true, if the configured forwarding mode is proactive, else false
106 * @deprecated replaced by isProactive() API of ForwardingMode property
109 public boolean isProactive() {
110 return Integer.parseInt(getMode()) == ForwardingMode.PROACTIVE_FORWARDING;
113 public static long getSerialversionuid() {
114 return serialVersionUID;
117 public Status validate() {
118 Status validCheck = validateNodeId();
119 if (validCheck.isSuccess()) {
120 validCheck = validateNodeProperties();
125 private Status validateNodeId() {
126 if (nodeId == null || nodeId.isEmpty()) {
127 return new Status(StatusCode.BADREQUEST, "NodeId cannot be empty");
129 return new Status(StatusCode.SUCCESS);
132 private Status validateNodeProperties() {
133 if (nodeProperties == null) {
134 return new Status(StatusCode.BADREQUEST, "nodeProperties cannot be null");
136 return new Status(StatusCode.SUCCESS);
140 public int hashCode() {
141 final int prime = 31;
143 result = prime * result + ((nodeId == null) ? 0 : nodeId.hashCode());
144 result = prime * result + ((nodeProperties == null) ? 0 : nodeProperties.hashCode());
149 public boolean equals(Object obj) {
156 if (getClass() != obj.getClass()) {
159 SwitchConfig other = (SwitchConfig) obj;
160 if (nodeId == null) {
161 if (other.nodeId != null) {
164 } else if (!nodeId.equals(other.nodeId)) {
167 if (nodeProperties == null) {
168 if (other.nodeProperties != null) {
171 } else if (!nodeProperties.equals(other.nodeProperties)) {
178 public String toString() {
179 return ("SwitchConfig [Node=" + nodeId + ", Properties=" + nodeProperties + "]");
183 * Implement clonable interface
186 public SwitchConfig clone() {
187 Map<String, Property> nodeProperties = (this.nodeProperties == null) ? null : new HashMap<String, Property>(
188 this.nodeProperties);
189 return new SwitchConfig(this.nodeId, nodeProperties);