3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.switchmanager;
12 import java.io.Serializable;
13 import java.lang.reflect.Field;
14 import java.util.ArrayList;
15 import java.util.List;
17 import org.opendaylight.controller.configuration.ConfigurationObject;
18 import org.opendaylight.controller.sal.core.Node;
19 import org.opendaylight.controller.sal.core.NodeConnector;
20 import org.opendaylight.controller.sal.utils.GUIField;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * The class represents a Span Port configuration for a network node.
27 public class SpanConfig extends ConfigurationObject implements Serializable {
28 protected static final Logger logger = LoggerFactory
29 .getLogger(SpanConfig.class);
30 private static final long serialVersionUID = 1L;
31 private static final String guiFields[] = { GUIField.NODE.toString(),
32 GUIField.SPANPORTS.toString() };
34 // Order matters: JSP file expects following fields in the following order
35 private String nodeId;
36 private String spanPort;
41 public String getNodeId() {
45 public String getSpanPort() {
49 public Node getNode() {
50 return Node.fromString(nodeId);
53 private boolean hasValidNodeId() {
54 return (getNode() != null);
57 private boolean hasValidSpanPort() {
58 return (spanPort != null && !spanPort.isEmpty());
61 public boolean isValidConfig() {
62 return (hasValidNodeId() && hasValidSpanPort());
66 public int hashCode() {
69 result = prime * result + ((nodeId == null) ? 0 : nodeId.hashCode());
70 result = prime * result
71 + ((spanPort == null) ? 0 : spanPort.hashCode());
76 public boolean equals(Object obj) {
83 if (getClass() != obj.getClass()) {
86 SpanConfig other = (SpanConfig) obj;
88 if (other.nodeId != null) {
91 } else if (!nodeId.equals(other.nodeId)) {
94 if (spanPort == null) {
95 if (other.spanPort != null) {
98 } else if (!spanPort.equals(other.spanPort)) {
104 public static ArrayList<String> getFieldsNames() {
105 ArrayList<String> fieldList = new ArrayList<String>();
106 for (Field fld : SpanConfig.class.getDeclaredFields()) {
107 fieldList.add(fld.getName());
109 //remove the two static fields
110 for (short i = 0; i < 2; i++) {
116 public static List<String> getGuiFieldsNames() {
117 List<String> fieldList = new ArrayList<String>();
118 for (String str : guiFields) {
124 public ArrayList<NodeConnector> getPortArrayList() {
125 ArrayList<NodeConnector> portList = new ArrayList<NodeConnector>();
126 String[] elemArray = spanPort.split(",");
127 for (String elem : elemArray) {
128 NodeConnector nodeConnector = NodeConnector.fromString(elem);
129 if (nodeConnector != null) {
130 portList.add(nodeConnector);
136 public boolean matchNode(String nodeId) {
137 return this.nodeId.equals(nodeId);
141 public String toString() {
142 return ("SpanConfig [nodeId=" + nodeId + ", spanPort=" + spanPort + "]");