blob: 0a4c70576ab3da27681d6c83afd6aa12953cdb72 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.device;
tomd1900f32014-09-03 14:08:16 -070017
Brian O'Connorabafb502014-12-02 22:26:20 -080018import org.onosproject.net.AbstractDescription;
19import org.onosproject.net.SparseAnnotations;
alshabib7911a052014-10-16 17:49:37 -070020import org.onlab.packet.ChassisId;
tom27ae0e62014-10-01 20:35:01 -070021
tomd1900f32014-09-03 14:08:16 -070022import java.net.URI;
23
tomeadbb462014-09-07 16:10:19 -070024import static com.google.common.base.MoreObjects.toStringHelper;
tomd1900f32014-09-03 14:08:16 -070025import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorabafb502014-12-02 22:26:20 -080026import static org.onosproject.net.Device.Type;
HIGUCHI Yuta703a5af2015-11-18 23:43:50 -080027import com.google.common.base.Objects;
tomd1900f32014-09-03 14:08:16 -070028
29/**
30 * Default implementation of immutable device description entity.
31 */
tomf5d85d42014-10-02 05:27:56 -070032public class DefaultDeviceDescription extends AbstractDescription
tom27ae0e62014-10-01 20:35:01 -070033 implements DeviceDescription {
tomd1900f32014-09-03 14:08:16 -070034 private final URI uri;
35 private final Type type;
36 private final String manufacturer;
37 private final String hwVersion;
38 private final String swVersion;
39 private final String serialNumber;
alshabib7911a052014-10-16 17:49:37 -070040 private final ChassisId chassisId;
helenyrwufd296b62016-06-22 17:43:02 -070041 private final boolean defaultAvailable;
tomd1900f32014-09-03 14:08:16 -070042
43 /**
44 * Creates a device description using the supplied information.
45 *
46 * @param uri device URI
47 * @param type device type
48 * @param manufacturer device manufacturer
49 * @param hwVersion device HW version
50 * @param swVersion device SW version
51 * @param serialNumber device serial number
Marc De Leenheerb473b9d2015-02-06 15:21:03 -080052 * @param chassis chassis id
tom27ae0e62014-10-01 20:35:01 -070053 * @param annotations optional key/value annotations map
tomd1900f32014-09-03 14:08:16 -070054 */
55 public DefaultDeviceDescription(URI uri, Type type, String manufacturer,
56 String hwVersion, String swVersion,
alshabib7911a052014-10-16 17:49:37 -070057 String serialNumber, ChassisId chassis,
tomf5d85d42014-10-02 05:27:56 -070058 SparseAnnotations... annotations) {
helenyrwufd296b62016-06-22 17:43:02 -070059 this(uri, type, manufacturer, hwVersion, swVersion, serialNumber,
60 chassis, true, annotations);
61 }
62
63 /**
64 * Creates a device description using the supplied information.
65 *
66 * @param uri device URI
67 * @param type device type
68 * @param manufacturer device manufacturer
69 * @param hwVersion device HW version
70 * @param swVersion device SW version
71 * @param serialNumber device serial number
72 * @param chassis chassis id
73 * @param defaultAvailable optional whether device is by default available
74 * @param annotations optional key/value annotations map
75 */
76 public DefaultDeviceDescription(URI uri, Type type, String manufacturer,
77 String hwVersion, String swVersion,
78 String serialNumber, ChassisId chassis,
79 boolean defaultAvailable,
80 SparseAnnotations... annotations) {
tom27ae0e62014-10-01 20:35:01 -070081 super(annotations);
tomd1900f32014-09-03 14:08:16 -070082 this.uri = checkNotNull(uri, "Device URI cannot be null");
83 this.type = checkNotNull(type, "Device type cannot be null");
84 this.manufacturer = manufacturer;
85 this.hwVersion = hwVersion;
86 this.swVersion = swVersion;
87 this.serialNumber = serialNumber;
alshabib7911a052014-10-16 17:49:37 -070088 this.chassisId = chassis;
helenyrwufd296b62016-06-22 17:43:02 -070089 this.defaultAvailable = defaultAvailable;
tomd1900f32014-09-03 14:08:16 -070090 }
91
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070092 /**
93 * Creates a device description using the supplied information.
94 * @param base DeviceDescription to basic information
95 * @param annotations Annotations to use.
96 */
97 public DefaultDeviceDescription(DeviceDescription base,
98 SparseAnnotations... annotations) {
Jonathan Hartd9df7bd2015-11-10 17:10:25 -080099 this(base.deviceUri(), base.type(), base.manufacturer(),
Yuta HIGUCHI55710e72014-10-02 14:58:32 -0700100 base.hwVersion(), base.swVersion(), base.serialNumber(),
helenyrwufd296b62016-06-22 17:43:02 -0700101 base.chassisId(), base.isDefaultAvailable(), annotations);
Yuta HIGUCHI55710e72014-10-02 14:58:32 -0700102 }
103
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700104 /**
105 * Creates a device description using the supplied information.
106 * @param base DeviceDescription to basic information (except for type)
107 * @param type device type
108 * @param annotations Annotations to use.
109 */
helenyrwufd296b62016-06-22 17:43:02 -0700110 public DefaultDeviceDescription(DeviceDescription base, Type type,
111 SparseAnnotations... annotations) {
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800112 this(base.deviceUri(), type, base.manufacturer(),
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700113 base.hwVersion(), base.swVersion(), base.serialNumber(),
helenyrwufd296b62016-06-22 17:43:02 -0700114 base.chassisId(), base.isDefaultAvailable(), annotations);
115 }
116
117 /**
118 * Creates a device description using the supplied information.
119 *
120 * @param base DeviceDescription to basic information (except for defaultAvailable)
121 * @param defaultAvailable whether device should be made available by default
122 * @param annotations Annotations to use.
123 */
124 public DefaultDeviceDescription(DeviceDescription base,
125 boolean defaultAvailable,
126 SparseAnnotations... annotations) {
127 this(base.deviceUri(), base.type(), base.manufacturer(),
128 base.hwVersion(), base.swVersion(), base.serialNumber(),
129 base.chassisId(), defaultAvailable, annotations);
Sahil Lele3a0cdd52015-07-21 14:16:31 -0700130 }
131
tomd1900f32014-09-03 14:08:16 -0700132 @Override
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800133 public URI deviceUri() {
tomd1900f32014-09-03 14:08:16 -0700134 return uri;
135 }
136
137 @Override
138 public Type type() {
139 return type;
140 }
141
142 @Override
143 public String manufacturer() {
144 return manufacturer;
145 }
146
147 @Override
148 public String hwVersion() {
149 return hwVersion;
150 }
151
152 @Override
153 public String swVersion() {
154 return swVersion;
155 }
156
157 @Override
158 public String serialNumber() {
159 return serialNumber;
160 }
161
162 @Override
alshabib7911a052014-10-16 17:49:37 -0700163 public ChassisId chassisId() {
164 return chassisId;
165 }
166
167 @Override
helenyrwufd296b62016-06-22 17:43:02 -0700168 public boolean isDefaultAvailable() {
169 return defaultAvailable;
170 }
171
172 @Override
tomd1900f32014-09-03 14:08:16 -0700173 public String toString() {
174 return toStringHelper(this)
175 .add("uri", uri).add("type", type).add("mfr", manufacturer)
176 .add("hw", hwVersion).add("sw", swVersion)
177 .add("serial", serialNumber)
Pavel Likin9d49f542015-12-13 15:04:55 +0300178 .add("annotations", annotations())
tomd1900f32014-09-03 14:08:16 -0700179 .toString();
180 }
181
HIGUCHI Yuta703a5af2015-11-18 23:43:50 -0800182 @Override
183 public int hashCode() {
184 return Objects.hashCode(super.hashCode(), uri, type, manufacturer,
helenyrwufd296b62016-06-22 17:43:02 -0700185 hwVersion, swVersion, serialNumber, chassisId,
186 defaultAvailable);
HIGUCHI Yuta703a5af2015-11-18 23:43:50 -0800187 }
188
189 @Override
190 public boolean equals(Object object) {
191 if (object instanceof DefaultDeviceDescription) {
192 if (!super.equals(object)) {
193 return false;
194 }
195 DefaultDeviceDescription that = (DefaultDeviceDescription) object;
196 return Objects.equal(this.uri, that.uri)
197 && Objects.equal(this.type, that.type)
198 && Objects.equal(this.manufacturer, that.manufacturer)
199 && Objects.equal(this.hwVersion, that.hwVersion)
200 && Objects.equal(this.swVersion, that.swVersion)
201 && Objects.equal(this.serialNumber, that.serialNumber)
helenyrwufd296b62016-06-22 17:43:02 -0700202 && Objects.equal(this.chassisId, that.chassisId)
203 && Objects.equal(this.defaultAvailable, that.defaultAvailable);
HIGUCHI Yuta703a5af2015-11-18 23:43:50 -0800204 }
205 return false;
206 }
207
Yuta HIGUCHIf1f1d322014-10-07 21:09:56 -0700208 // default constructor for serialization
Ray Milkeya6b21122016-10-24 17:18:35 -0700209 DefaultDeviceDescription() {
Yuta HIGUCHIf1f1d322014-10-07 21:09:56 -0700210 this.uri = null;
211 this.type = null;
212 this.manufacturer = null;
213 this.hwVersion = null;
214 this.swVersion = null;
215 this.serialNumber = null;
alshabib7911a052014-10-16 17:49:37 -0700216 this.chassisId = null;
helenyrwufd296b62016-06-22 17:43:02 -0700217 this.defaultAvailable = true;
Yuta HIGUCHIf1f1d322014-10-07 21:09:56 -0700218 }
tomd1900f32014-09-03 14:08:16 -0700219}