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.sal.core.Node;
18 import org.opendaylight.controller.sal.core.NodeConnector;
19 import org.opendaylight.controller.sal.utils.GUIField;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * The class represents a Span Port configuration for a network node.
26 public class SpanConfig implements Serializable {
27 protected static final Logger logger = LoggerFactory
28 .getLogger(SpanConfig.class);
29 private static final long serialVersionUID = 1L;
30 private static final String guiFields[] = { GUIField.NODE.toString(),
31 GUIField.SPANPORTS.toString() };
33 // Order matters: JSP file expects following fields in the following order
34 private String nodeId;
35 private String spanPort;
40 public String getNodeId() {
44 public String getSpanPort() {
48 public Node getNode() {
49 return Node.fromString(nodeId);
52 private boolean hasValidNodeId() {
53 return (getNode() != null);
56 private boolean hasValidSpanPort() {
57 return (spanPort != null && !spanPort.isEmpty());
60 public boolean isValidConfig() {
61 return (hasValidNodeId() && hasValidSpanPort());
65 public int hashCode() {
68 result = prime * result + ((nodeId == null) ? 0 : nodeId.hashCode());
69 result = prime * result
70 + ((spanPort == null) ? 0 : spanPort.hashCode());
75 public boolean equals(Object obj) {
80 if (getClass() != obj.getClass())
82 SpanConfig other = (SpanConfig) obj;
84 if (other.nodeId != null)
86 } else if (!nodeId.equals(other.nodeId))
88 if (spanPort == null) {
89 if (other.spanPort != null)
91 } else if (!spanPort.equals(other.spanPort))
96 public static ArrayList<String> getFieldsNames() {
97 ArrayList<String> fieldList = new ArrayList<String>();
98 for (Field fld : SpanConfig.class.getDeclaredFields()) {
99 fieldList.add(fld.getName());
101 //remove the two static fields
102 for (short i = 0; i < 2; i++) {
108 public static List<String> getGuiFieldsNames() {
109 List<String> fieldList = new ArrayList<String>();
110 for (String str : guiFields) {
116 public ArrayList<NodeConnector> getPortArrayList() {
117 ArrayList<NodeConnector> portList = new ArrayList<NodeConnector>();
118 String[] elemArray = spanPort.split(",");
119 for (String elem : elemArray) {
120 NodeConnector nodeConnector = NodeConnector.fromString(elem);
121 if (nodeConnector != null) {
122 portList.add(nodeConnector);
128 public boolean matchNode(String nodeId) {
129 return this.nodeId.equals(nodeId);
133 public String toString() {
134 return ("SpanConfig [nodeId=" + nodeId + ", spanPort=" + spanPort + "]");