Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 3 | * |
| 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'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.device; |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 17 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 18 | import org.onosproject.net.AbstractDescription; |
| 19 | import org.onosproject.net.SparseAnnotations; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 20 | import org.onlab.packet.ChassisId; |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 21 | |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 22 | import java.net.URI; |
| 23 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 24 | import static com.google.common.base.MoreObjects.toStringHelper; |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 25 | import static com.google.common.base.Preconditions.checkNotNull; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 26 | import static org.onosproject.net.Device.Type; |
HIGUCHI Yuta | 703a5af | 2015-11-18 23:43:50 -0800 | [diff] [blame] | 27 | import com.google.common.base.Objects; |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Default implementation of immutable device description entity. |
| 31 | */ |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 32 | public class DefaultDeviceDescription extends AbstractDescription |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 33 | implements DeviceDescription { |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 34 | 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; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 40 | private final ChassisId chassisId; |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 41 | private final boolean defaultAvailable; |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 42 | |
| 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 Leenheer | b473b9d | 2015-02-06 15:21:03 -0800 | [diff] [blame] | 52 | * @param chassis chassis id |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 53 | * @param annotations optional key/value annotations map |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 54 | */ |
| 55 | public DefaultDeviceDescription(URI uri, Type type, String manufacturer, |
| 56 | String hwVersion, String swVersion, |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 57 | String serialNumber, ChassisId chassis, |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 58 | SparseAnnotations... annotations) { |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 59 | 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) { |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 81 | super(annotations); |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 82 | 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; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 88 | this.chassisId = chassis; |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 89 | this.defaultAvailable = defaultAvailable; |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Yuta HIGUCHI | 55710e7 | 2014-10-02 14:58:32 -0700 | [diff] [blame] | 92 | /** |
| 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 Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 99 | this(base.deviceUri(), base.type(), base.manufacturer(), |
Yuta HIGUCHI | 55710e7 | 2014-10-02 14:58:32 -0700 | [diff] [blame] | 100 | base.hwVersion(), base.swVersion(), base.serialNumber(), |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 101 | base.chassisId(), base.isDefaultAvailable(), annotations); |
Yuta HIGUCHI | 55710e7 | 2014-10-02 14:58:32 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Sahil Lele | 3a0cdd5 | 2015-07-21 14:16:31 -0700 | [diff] [blame] | 104 | /** |
| 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 | */ |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 110 | public DefaultDeviceDescription(DeviceDescription base, Type type, |
| 111 | SparseAnnotations... annotations) { |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 112 | this(base.deviceUri(), type, base.manufacturer(), |
Sahil Lele | 3a0cdd5 | 2015-07-21 14:16:31 -0700 | [diff] [blame] | 113 | base.hwVersion(), base.swVersion(), base.serialNumber(), |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 114 | 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 Lele | 3a0cdd5 | 2015-07-21 14:16:31 -0700 | [diff] [blame] | 130 | } |
| 131 | |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 132 | @Override |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 133 | public URI deviceUri() { |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 134 | 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 |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 163 | public ChassisId chassisId() { |
| 164 | return chassisId; |
| 165 | } |
| 166 | |
| 167 | @Override |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 168 | public boolean isDefaultAvailable() { |
| 169 | return defaultAvailable; |
| 170 | } |
| 171 | |
| 172 | @Override |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 173 | 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 Likin | 9d49f54 | 2015-12-13 15:04:55 +0300 | [diff] [blame] | 178 | .add("annotations", annotations()) |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 179 | .toString(); |
| 180 | } |
| 181 | |
HIGUCHI Yuta | 703a5af | 2015-11-18 23:43:50 -0800 | [diff] [blame] | 182 | @Override |
| 183 | public int hashCode() { |
| 184 | return Objects.hashCode(super.hashCode(), uri, type, manufacturer, |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 185 | hwVersion, swVersion, serialNumber, chassisId, |
| 186 | defaultAvailable); |
HIGUCHI Yuta | 703a5af | 2015-11-18 23:43:50 -0800 | [diff] [blame] | 187 | } |
| 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) |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 202 | && Objects.equal(this.chassisId, that.chassisId) |
| 203 | && Objects.equal(this.defaultAvailable, that.defaultAvailable); |
HIGUCHI Yuta | 703a5af | 2015-11-18 23:43:50 -0800 | [diff] [blame] | 204 | } |
| 205 | return false; |
| 206 | } |
| 207 | |
Yuta HIGUCHI | f1f1d32 | 2014-10-07 21:09:56 -0700 | [diff] [blame] | 208 | // default constructor for serialization |
| 209 | private DefaultDeviceDescription() { |
| 210 | this.uri = null; |
| 211 | this.type = null; |
| 212 | this.manufacturer = null; |
| 213 | this.hwVersion = null; |
| 214 | this.swVersion = null; |
| 215 | this.serialNumber = null; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 216 | this.chassisId = null; |
helenyrwu | fd296b6 | 2016-06-22 17:43:02 -0700 | [diff] [blame] | 217 | this.defaultAvailable = true; |
Yuta HIGUCHI | f1f1d32 | 2014-10-07 21:09:56 -0700 | [diff] [blame] | 218 | } |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 219 | } |