blob: 742616371e09fe8031cbd819ec873bff8d22aa79 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
2* Copyright 2012 Big Switch Networks, Inc.
3* Originally created by David Erickson, Stanford University
4*
5* Licensed under the Apache License, Version 2.0 (the "License"); you may
6* not use this file except in compliance with the License. You may obtain
7* a copy of the License at
8*
9* http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14* License for the specific language governing permissions and limitations
15* under the License.
16**/
17
18package net.floodlightcontroller.devicemanager;
19
20import net.floodlightcontroller.core.web.serializers.DPIDSerializer;
21
22import org.codehaus.jackson.map.annotate.JsonSerialize;
Pankaj Berde98478422013-09-10 13:53:26 -070023import org.codehaus.jackson.map.ser.ToStringSerializer;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080024
25/**
26 * A simple switch DPID/port pair
27 * @author readams
28 *
29 */
30public class SwitchPort {
31 @JsonSerialize(using=ToStringSerializer.class)
32 public enum ErrorStatus {
33 DUPLICATE_DEVICE("duplicate-device");
34
35 private String value;
36 ErrorStatus(String v) {
37 value = v;
38 }
39
40 @Override
41 public String toString() {
42 return value;
43 }
44
45 public static ErrorStatus fromString(String str) {
46 for (ErrorStatus m : ErrorStatus.values()) {
47 if (m.value.equals(str)) {
48 return m;
49 }
50 }
51 return null;
52 }
53 }
54
55 protected long switchDPID;
56 protected int port;
57 ErrorStatus errorStatus;
58
59 /**
60 * Simple constructor
61 * @param switchDPID the dpid
62 * @param port the port
63 * @param errorStatus any error status for the switch port
64 */
65 public SwitchPort(long switchDPID, int port, ErrorStatus errorStatus) {
66 super();
67 this.switchDPID = switchDPID;
68 this.port = port;
69 this.errorStatus = errorStatus;
70 }
71
72 /**
73 * Simple constructor
74 * @param switchDPID the dpid
75 * @param port the port
76 */
77 public SwitchPort(long switchDPID, int port) {
78 super();
79 this.switchDPID = switchDPID;
80 this.port = port;
81 this.errorStatus = null;
82 }
83
84 // ***************
85 // Getters/Setters
86 // ***************
87
88 @JsonSerialize(using=DPIDSerializer.class)
89 public long getSwitchDPID() {
90 return switchDPID;
91 }
92
93 public int getPort() {
94 return port;
95 }
96
97 public ErrorStatus getErrorStatus() {
98 return errorStatus;
99 }
100
101 // ******
102 // Object
103 // ******
104
105 @Override
106 public int hashCode() {
107 final int prime = 31;
108 int result = 1;
109 result = prime * result
110 + ((errorStatus == null)
111 ? 0
112 : errorStatus.hashCode());
113 result = prime * result + port;
114 result = prime * result + (int) (switchDPID ^ (switchDPID >>> 32));
115 return result;
116 }
117
118 @Override
119 public boolean equals(Object obj) {
120 if (this == obj) return true;
121 if (obj == null) return false;
122 if (getClass() != obj.getClass()) return false;
123 SwitchPort other = (SwitchPort) obj;
124 if (errorStatus != other.errorStatus) return false;
125 if (port != other.port) return false;
126 if (switchDPID != other.switchDPID) return false;
127 return true;
128 }
129
130 @Override
131 public String toString() {
132 return "SwitchPort [switchDPID=" + switchDPID + ", port=" + port
133 + ", errorStatus=" + errorStatus + "]";
134 }
135
136}