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; |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 41 | |
| 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 Leenheer | b473b9d | 2015-02-06 15:21:03 -0800 | [diff] [blame] | 51 | * @param chassis chassis id |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 52 | * @param annotations optional key/value annotations map |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 53 | */ |
| 54 | public DefaultDeviceDescription(URI uri, Type type, String manufacturer, |
| 55 | String hwVersion, String swVersion, |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 56 | String serialNumber, ChassisId chassis, |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 57 | SparseAnnotations... annotations) { |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 58 | super(annotations); |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 59 | 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; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 65 | this.chassisId = chassis; |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Yuta HIGUCHI | 55710e7 | 2014-10-02 14:58:32 -0700 | [diff] [blame] | 68 | /** |
| 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 Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 75 | this(base.deviceUri(), base.type(), base.manufacturer(), |
Yuta HIGUCHI | 55710e7 | 2014-10-02 14:58:32 -0700 | [diff] [blame] | 76 | base.hwVersion(), base.swVersion(), base.serialNumber(), |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 77 | base.chassisId(), annotations); |
Yuta HIGUCHI | 55710e7 | 2014-10-02 14:58:32 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Sahil Lele | 3a0cdd5 | 2015-07-21 14:16:31 -0700 | [diff] [blame] | 80 | /** |
| 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 Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 87 | this(base.deviceUri(), type, base.manufacturer(), |
Sahil Lele | 3a0cdd5 | 2015-07-21 14:16:31 -0700 | [diff] [blame] | 88 | base.hwVersion(), base.swVersion(), base.serialNumber(), |
| 89 | base.chassisId(), annotations); |
| 90 | } |
| 91 | |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 92 | @Override |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 93 | public URI deviceUri() { |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 94 | 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 |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 123 | public ChassisId chassisId() { |
| 124 | return chassisId; |
| 125 | } |
| 126 | |
| 127 | @Override |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 128 | 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 Likin | 9d49f54 | 2015-12-13 15:04:55 +0300 | [diff] [blame] | 133 | .add("annotations", annotations()) |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 134 | .toString(); |
| 135 | } |
| 136 | |
HIGUCHI Yuta | 703a5af | 2015-11-18 23:43:50 -0800 | [diff] [blame] | 137 | @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 HIGUCHI | f1f1d32 | 2014-10-07 21:09:56 -0700 | [diff] [blame] | 161 | // 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; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 169 | this.chassisId = null; |
Yuta HIGUCHI | f1f1d32 | 2014-10-07 21:09:56 -0700 | [diff] [blame] | 170 | } |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 171 | } |