blob: e3aa2edf907c2ad882b9047c91daf8d840609a8b [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
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 */
tomd1900f32014-09-03 14:08:16 -070016package org.onlab.onos.net.device;
17
tomf5d85d42014-10-02 05:27:56 -070018import org.onlab.onos.net.AbstractDescription;
19import org.onlab.onos.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;
26import static org.onlab.onos.net.Device.Type;
27
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
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080050 * @param chassis chasis 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) {
74 this(base.deviceURI(), base.type(), base.manufacturer(),
75 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
tomd1900f32014-09-03 14:08:16 -070079 @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
alshabib7911a052014-10-16 17:49:37 -0700110 public ChassisId chassisId() {
111 return chassisId;
112 }
113
114 @Override
tomd1900f32014-09-03 14:08:16 -0700115 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 HIGUCHIf1f1d322014-10-07 21:09:56 -0700123 // 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;
alshabib7911a052014-10-16 17:49:37 -0700131 this.chassisId = null;
Yuta HIGUCHIf1f1d322014-10-07 21:09:56 -0700132 }
tomd1900f32014-09-03 14:08:16 -0700133}