blob: 1bbdaf77913a9569048bd9a0bc5b72abf61da40f [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
tom27ae0e62014-10-01 20:35:01 -070050 * @param annotations optional key/value annotations map
tomd1900f32014-09-03 14:08:16 -070051 */
52 public DefaultDeviceDescription(URI uri, Type type, String manufacturer,
53 String hwVersion, String swVersion,
alshabib7911a052014-10-16 17:49:37 -070054 String serialNumber, ChassisId chassis,
tomf5d85d42014-10-02 05:27:56 -070055 SparseAnnotations... annotations) {
tom27ae0e62014-10-01 20:35:01 -070056 super(annotations);
tomd1900f32014-09-03 14:08:16 -070057 this.uri = checkNotNull(uri, "Device URI cannot be null");
58 this.type = checkNotNull(type, "Device type cannot be null");
59 this.manufacturer = manufacturer;
60 this.hwVersion = hwVersion;
61 this.swVersion = swVersion;
62 this.serialNumber = serialNumber;
alshabib7911a052014-10-16 17:49:37 -070063 this.chassisId = chassis;
tomd1900f32014-09-03 14:08:16 -070064 }
65
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070066 /**
67 * Creates a device description using the supplied information.
68 * @param base DeviceDescription to basic information
69 * @param annotations Annotations to use.
70 */
71 public DefaultDeviceDescription(DeviceDescription base,
72 SparseAnnotations... annotations) {
73 this(base.deviceURI(), base.type(), base.manufacturer(),
74 base.hwVersion(), base.swVersion(), base.serialNumber(),
alshabib7911a052014-10-16 17:49:37 -070075 base.chassisId(), annotations);
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070076 }
77
tomd1900f32014-09-03 14:08:16 -070078 @Override
79 public URI deviceURI() {
80 return uri;
81 }
82
83 @Override
84 public Type type() {
85 return type;
86 }
87
88 @Override
89 public String manufacturer() {
90 return manufacturer;
91 }
92
93 @Override
94 public String hwVersion() {
95 return hwVersion;
96 }
97
98 @Override
99 public String swVersion() {
100 return swVersion;
101 }
102
103 @Override
104 public String serialNumber() {
105 return serialNumber;
106 }
107
108 @Override
alshabib7911a052014-10-16 17:49:37 -0700109 public ChassisId chassisId() {
110 return chassisId;
111 }
112
113 @Override
tomd1900f32014-09-03 14:08:16 -0700114 public String toString() {
115 return toStringHelper(this)
116 .add("uri", uri).add("type", type).add("mfr", manufacturer)
117 .add("hw", hwVersion).add("sw", swVersion)
118 .add("serial", serialNumber)
119 .toString();
120 }
121
Yuta HIGUCHIf1f1d322014-10-07 21:09:56 -0700122 // default constructor for serialization
123 private DefaultDeviceDescription() {
124 this.uri = null;
125 this.type = null;
126 this.manufacturer = null;
127 this.hwVersion = null;
128 this.swVersion = null;
129 this.serialNumber = null;
alshabib7911a052014-10-16 17:49:37 -0700130 this.chassisId = null;
Yuta HIGUCHIf1f1d322014-10-07 21:09:56 -0700131 }
tomd1900f32014-09-03 14:08:16 -0700132}