blob: 0fcc800d6b45de3e8d8cdd5053de6f08d479d4d3 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 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;
tomd1900f32014-09-03 14:08:16 -070027
28/**
29 * Default implementation of immutable device description entity.
30 */
tomf5d85d42014-10-02 05:27:56 -070031public class DefaultDeviceDescription extends AbstractDescription
tom27ae0e62014-10-01 20:35:01 -070032 implements DeviceDescription {
tomd1900f32014-09-03 14:08:16 -070033 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;
alshabib7911a052014-10-16 17:49:37 -070039 private final ChassisId chassisId;
tomd1900f32014-09-03 14:08:16 -070040
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 Leenheerb473b9d2015-02-06 15:21:03 -080050 * @param chassis chassis id
tom27ae0e62014-10-01 20:35:01 -070051 * @param annotations optional key/value annotations map
tomd1900f32014-09-03 14:08:16 -070052 */
53 public DefaultDeviceDescription(URI uri, Type type, String manufacturer,
54 String hwVersion, String swVersion,
alshabib7911a052014-10-16 17:49:37 -070055 String serialNumber, ChassisId chassis,
tomf5d85d42014-10-02 05:27:56 -070056 SparseAnnotations... annotations) {
tom27ae0e62014-10-01 20:35:01 -070057 super(annotations);
tomd1900f32014-09-03 14:08:16 -070058 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;
alshabib7911a052014-10-16 17:49:37 -070064 this.chassisId = chassis;
tomd1900f32014-09-03 14:08:16 -070065 }
66
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070067 /**
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) {
Jonathan Hartd9df7bd2015-11-10 17:10:25 -080074 this(base.deviceUri(), base.type(), base.manufacturer(),
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070075 base.hwVersion(), base.swVersion(), base.serialNumber(),
alshabib7911a052014-10-16 17:49:37 -070076 base.chassisId(), annotations);
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070077 }
78
Sahil Lele3a0cdd52015-07-21 14:16:31 -070079 /**
80 * Creates a device description using the supplied information.
81 * @param base DeviceDescription to basic information (except for type)
82 * @param type device type
83 * @param annotations Annotations to use.
84 */
85 public DefaultDeviceDescription(DeviceDescription base, Type type, SparseAnnotations... annotations) {
Jonathan Hartd9df7bd2015-11-10 17:10:25 -080086 this(base.deviceUri(), type, base.manufacturer(),
Sahil Lele3a0cdd52015-07-21 14:16:31 -070087 base.hwVersion(), base.swVersion(), base.serialNumber(),
88 base.chassisId(), annotations);
89 }
90
tomd1900f32014-09-03 14:08:16 -070091 @Override
Jonathan Hartd9df7bd2015-11-10 17:10:25 -080092 public URI deviceUri() {
tomd1900f32014-09-03 14:08:16 -070093 return uri;
94 }
95
96 @Override
97 public Type type() {
98 return type;
99 }
100
101 @Override
102 public String manufacturer() {
103 return manufacturer;
104 }
105
106 @Override
107 public String hwVersion() {
108 return hwVersion;
109 }
110
111 @Override
112 public String swVersion() {
113 return swVersion;
114 }
115
116 @Override
117 public String serialNumber() {
118 return serialNumber;
119 }
120
121 @Override
alshabib7911a052014-10-16 17:49:37 -0700122 public ChassisId chassisId() {
123 return chassisId;
124 }
125
126 @Override
tomd1900f32014-09-03 14:08:16 -0700127 public String toString() {
128 return toStringHelper(this)
129 .add("uri", uri).add("type", type).add("mfr", manufacturer)
130 .add("hw", hwVersion).add("sw", swVersion)
131 .add("serial", serialNumber)
132 .toString();
133 }
134
Yuta HIGUCHIf1f1d322014-10-07 21:09:56 -0700135 // default constructor for serialization
136 private DefaultDeviceDescription() {
137 this.uri = null;
138 this.type = null;
139 this.manufacturer = null;
140 this.hwVersion = null;
141 this.swVersion = null;
142 this.serialNumber = null;
alshabib7911a052014-10-16 17:49:37 -0700143 this.chassisId = null;
Yuta HIGUCHIf1f1d322014-10-07 21:09:56 -0700144 }
tomd1900f32014-09-03 14:08:16 -0700145}