blob: 72ec4ab6caa0e4cf324479ca1e0a20fbb90a65bf [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;
tomd1900f32014-09-03 14:08:16 -070041
42 /**
43 * Creates a device description using the supplied information.
44 *
45 * @param uri device URI
46 * @param type device type
47 * @param manufacturer device manufacturer
48 * @param hwVersion device HW version
49 * @param swVersion device SW version
50 * @param serialNumber device serial number
Marc De Leenheerb473b9d2015-02-06 15:21:03 -080051 * @param chassis chassis id
tom27ae0e62014-10-01 20:35:01 -070052 * @param annotations optional key/value annotations map
tomd1900f32014-09-03 14:08:16 -070053 */
54 public DefaultDeviceDescription(URI uri, Type type, String manufacturer,
55 String hwVersion, String swVersion,
alshabib7911a052014-10-16 17:49:37 -070056 String serialNumber, ChassisId chassis,
tomf5d85d42014-10-02 05:27:56 -070057 SparseAnnotations... annotations) {
tom27ae0e62014-10-01 20:35:01 -070058 super(annotations);
tomd1900f32014-09-03 14:08:16 -070059 this.uri = checkNotNull(uri, "Device URI cannot be null");
60 this.type = checkNotNull(type, "Device type cannot be null");
61 this.manufacturer = manufacturer;
62 this.hwVersion = hwVersion;
63 this.swVersion = swVersion;
64 this.serialNumber = serialNumber;
alshabib7911a052014-10-16 17:49:37 -070065 this.chassisId = chassis;
tomd1900f32014-09-03 14:08:16 -070066 }
67
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070068 /**
69 * Creates a device description using the supplied information.
70 * @param base DeviceDescription to basic information
71 * @param annotations Annotations to use.
72 */
73 public DefaultDeviceDescription(DeviceDescription base,
74 SparseAnnotations... annotations) {
Jonathan Hartd9df7bd2015-11-10 17:10:25 -080075 this(base.deviceUri(), base.type(), base.manufacturer(),
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070076 base.hwVersion(), base.swVersion(), base.serialNumber(),
alshabib7911a052014-10-16 17:49:37 -070077 base.chassisId(), annotations);
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070078 }
79
Sahil Lele3a0cdd52015-07-21 14:16:31 -070080 /**
81 * Creates a device description using the supplied information.
82 * @param base DeviceDescription to basic information (except for type)
83 * @param type device type
84 * @param annotations Annotations to use.
85 */
86 public DefaultDeviceDescription(DeviceDescription base, Type type, SparseAnnotations... annotations) {
Jonathan Hartd9df7bd2015-11-10 17:10:25 -080087 this(base.deviceUri(), type, base.manufacturer(),
Sahil Lele3a0cdd52015-07-21 14:16:31 -070088 base.hwVersion(), base.swVersion(), base.serialNumber(),
89 base.chassisId(), annotations);
90 }
91
tomd1900f32014-09-03 14:08:16 -070092 @Override
Jonathan Hartd9df7bd2015-11-10 17:10:25 -080093 public URI deviceUri() {
tomd1900f32014-09-03 14:08:16 -070094 return uri;
95 }
96
97 @Override
98 public Type type() {
99 return type;
100 }
101
102 @Override
103 public String manufacturer() {
104 return manufacturer;
105 }
106
107 @Override
108 public String hwVersion() {
109 return hwVersion;
110 }
111
112 @Override
113 public String swVersion() {
114 return swVersion;
115 }
116
117 @Override
118 public String serialNumber() {
119 return serialNumber;
120 }
121
122 @Override
alshabib7911a052014-10-16 17:49:37 -0700123 public ChassisId chassisId() {
124 return chassisId;
125 }
126
127 @Override
tomd1900f32014-09-03 14:08:16 -0700128 public String toString() {
129 return toStringHelper(this)
130 .add("uri", uri).add("type", type).add("mfr", manufacturer)
131 .add("hw", hwVersion).add("sw", swVersion)
132 .add("serial", serialNumber)
Pavel Likin9d49f542015-12-13 15:04:55 +0300133 .add("annotations", annotations())
tomd1900f32014-09-03 14:08:16 -0700134 .toString();
135 }
136
HIGUCHI Yuta703a5af2015-11-18 23:43:50 -0800137 @Override
138 public int hashCode() {
139 return Objects.hashCode(super.hashCode(), uri, type, manufacturer,
140 hwVersion, swVersion, serialNumber, chassisId);
141 }
142
143 @Override
144 public boolean equals(Object object) {
145 if (object instanceof DefaultDeviceDescription) {
146 if (!super.equals(object)) {
147 return false;
148 }
149 DefaultDeviceDescription that = (DefaultDeviceDescription) object;
150 return Objects.equal(this.uri, that.uri)
151 && Objects.equal(this.type, that.type)
152 && Objects.equal(this.manufacturer, that.manufacturer)
153 && Objects.equal(this.hwVersion, that.hwVersion)
154 && Objects.equal(this.swVersion, that.swVersion)
155 && Objects.equal(this.serialNumber, that.serialNumber)
156 && Objects.equal(this.chassisId, that.chassisId);
157 }
158 return false;
159 }
160
Yuta HIGUCHIf1f1d322014-10-07 21:09:56 -0700161 // default constructor for serialization
162 private DefaultDeviceDescription() {
163 this.uri = null;
164 this.type = null;
165 this.manufacturer = null;
166 this.hwVersion = null;
167 this.swVersion = null;
168 this.serialNumber = null;
alshabib7911a052014-10-16 17:49:37 -0700169 this.chassisId = null;
Yuta HIGUCHIf1f1d322014-10-07 21:09:56 -0700170 }
tomd1900f32014-09-03 14:08:16 -0700171}