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.ConstructionException;
18 import org.opendaylight.controller.sal.core.Node;
19 import org.opendaylight.controller.sal.core.NodeConnector;
20 import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
21 import org.opendaylight.controller.sal.utils.GUIField;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * The class represents a Span Port configuration for a network node.
28 public class SpanConfig implements Serializable {
29 protected static final Logger logger = LoggerFactory
30 .getLogger(SpanConfig.class);
31 private static final long serialVersionUID = 1L;
32 private static final String guiFields[] = { GUIField.NODE.toString(),
33 GUIField.SPANPORTS.toString() };
35 // Order matters: JSP file expects following fields in the following order
36 private String nodeId;
37 private String spanPort;
42 public String getNodeId() {
46 public String getSpanPort() {
50 public Node getNode() {
51 return Node.fromString(nodeId);
54 private boolean hasValidNodeId() {
55 return (getNode() != null);
58 private boolean hasValidSpanPort() {
59 return (spanPort != null && !spanPort.isEmpty());
62 public boolean isValidConfig() {
63 return (hasValidNodeId() && hasValidSpanPort());
67 public int hashCode() {
70 result = prime * result + ((nodeId == null) ? 0 : nodeId.hashCode());
71 result = prime * result
72 + ((spanPort == null) ? 0 : spanPort.hashCode());
77 public boolean equals(Object obj) {
82 if (getClass() != obj.getClass())
84 SpanConfig other = (SpanConfig) obj;
86 if (other.nodeId != null)
88 } else if (!nodeId.equals(other.nodeId))
90 if (spanPort == null) {
91 if (other.spanPort != null)
93 } else if (!spanPort.equals(other.spanPort))
98 public static ArrayList<String> getFieldsNames() {
99 ArrayList<String> fieldList = new ArrayList<String>();
100 for (Field fld : SpanConfig.class.getDeclaredFields()) {
101 fieldList.add(fld.getName());
103 //remove the two static fields
104 for (short i = 0; i < 2; i++) {
110 public static List<String> getGuiFieldsNames() {
111 List<String> fieldList = new ArrayList<String>();
112 for (String str : guiFields) {
118 public ArrayList<NodeConnector> getPortArrayList() {
119 Node node = Node.fromString(nodeId);
120 ArrayList<NodeConnector> portList = new ArrayList<NodeConnector>();
121 String[] elemArray = spanPort.split(",");
122 for (String elem : elemArray) {
123 if (elem.contains("-")) {
124 String[] limits = elem.split("-");
125 for (short j = Short.valueOf(limits[0]); j <= Short
126 .valueOf(limits[1]); j++) {
128 portList.add(new NodeConnector(
129 NodeConnectorIDType.OPENFLOW, Short.valueOf(j),
131 } catch (ConstructionException e) {
137 portList.add(new NodeConnector(
138 NodeConnectorIDType.OPENFLOW, Short.valueOf(elem),
140 } catch (NumberFormatException e) {
142 } catch (ConstructionException e) {
150 public boolean matchNode(String nodeId) {
151 return this.nodeId.equals(nodeId);
155 public String toString() {
156 return ("Span Config [nodeId=" + nodeId + " spanPort=" + spanPort + "]");