Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 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; |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Default implementation of immutable device description entity. |
| 30 | */ |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 31 | public class DefaultDeviceDescription extends AbstractDescription |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 32 | implements DeviceDescription { |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 33 | private final URI uri; |
| 34 | private final Type type; |
| 35 | private final String manufacturer; |
| 36 | private final String hwVersion; |
| 37 | private final String swVersion; |
| 38 | private final String serialNumber; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 39 | private final ChassisId chassisId; |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Creates a device description using the supplied information. |
| 43 | * |
| 44 | * @param uri device URI |
| 45 | * @param type device type |
| 46 | * @param manufacturer device manufacturer |
| 47 | * @param hwVersion device HW version |
| 48 | * @param swVersion device SW version |
| 49 | * @param serialNumber device serial number |
Marc De Leenheer | b473b9d | 2015-02-06 15:21:03 -0800 | [diff] [blame] | 50 | * @param chassis chassis id |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 51 | * @param annotations optional key/value annotations map |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 52 | */ |
| 53 | public DefaultDeviceDescription(URI uri, Type type, String manufacturer, |
| 54 | String hwVersion, String swVersion, |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 55 | String serialNumber, ChassisId chassis, |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 56 | SparseAnnotations... annotations) { |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 57 | super(annotations); |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 58 | this.uri = checkNotNull(uri, "Device URI cannot be null"); |
| 59 | this.type = checkNotNull(type, "Device type cannot be null"); |
| 60 | this.manufacturer = manufacturer; |
| 61 | this.hwVersion = hwVersion; |
| 62 | this.swVersion = swVersion; |
| 63 | this.serialNumber = serialNumber; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 64 | this.chassisId = chassis; |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Yuta HIGUCHI | 55710e7 | 2014-10-02 14:58:32 -0700 | [diff] [blame] | 67 | /** |
| 68 | * Creates a device description using the supplied information. |
| 69 | * @param base DeviceDescription to basic information |
| 70 | * @param annotations Annotations to use. |
| 71 | */ |
| 72 | public DefaultDeviceDescription(DeviceDescription base, |
| 73 | SparseAnnotations... annotations) { |
| 74 | this(base.deviceURI(), base.type(), base.manufacturer(), |
| 75 | base.hwVersion(), base.swVersion(), base.serialNumber(), |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 76 | base.chassisId(), annotations); |
Yuta HIGUCHI | 55710e7 | 2014-10-02 14:58:32 -0700 | [diff] [blame] | 77 | } |
| 78 | |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 79 | @Override |
| 80 | public URI deviceURI() { |
| 81 | return uri; |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public Type type() { |
| 86 | return type; |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public String manufacturer() { |
| 91 | return manufacturer; |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public String hwVersion() { |
| 96 | return hwVersion; |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public String swVersion() { |
| 101 | return swVersion; |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public String serialNumber() { |
| 106 | return serialNumber; |
| 107 | } |
| 108 | |
| 109 | @Override |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 110 | public ChassisId chassisId() { |
| 111 | return chassisId; |
| 112 | } |
| 113 | |
| 114 | @Override |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 115 | public String toString() { |
| 116 | return toStringHelper(this) |
| 117 | .add("uri", uri).add("type", type).add("mfr", manufacturer) |
| 118 | .add("hw", hwVersion).add("sw", swVersion) |
| 119 | .add("serial", serialNumber) |
| 120 | .toString(); |
| 121 | } |
| 122 | |
Yuta HIGUCHI | f1f1d32 | 2014-10-07 21:09:56 -0700 | [diff] [blame] | 123 | // default constructor for serialization |
| 124 | private DefaultDeviceDescription() { |
| 125 | this.uri = null; |
| 126 | this.type = null; |
| 127 | this.manufacturer = null; |
| 128 | this.hwVersion = null; |
| 129 | this.swVersion = null; |
| 130 | this.serialNumber = null; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 131 | this.chassisId = null; |
Yuta HIGUCHI | f1f1d32 | 2014-10-07 21:09:56 -0700 | [diff] [blame] | 132 | } |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 133 | } |