blob: ede2eb2b6990f6746a1bf7559fb64bd7c40051d5 [file] [log] [blame]
tomd1900f32014-09-03 14:08:16 -07001package org.onlab.onos.net.device;
2
tomf5d85d42014-10-02 05:27:56 -07003import org.onlab.onos.net.AbstractDescription;
4import org.onlab.onos.net.SparseAnnotations;
tom27ae0e62014-10-01 20:35:01 -07005
tomd1900f32014-09-03 14:08:16 -07006import java.net.URI;
7
tomeadbb462014-09-07 16:10:19 -07008import static com.google.common.base.MoreObjects.toStringHelper;
tomd1900f32014-09-03 14:08:16 -07009import static com.google.common.base.Preconditions.checkNotNull;
10import static org.onlab.onos.net.Device.Type;
11
12/**
13 * Default implementation of immutable device description entity.
14 */
tomf5d85d42014-10-02 05:27:56 -070015public class DefaultDeviceDescription extends AbstractDescription
tom27ae0e62014-10-01 20:35:01 -070016 implements DeviceDescription {
tomd1900f32014-09-03 14:08:16 -070017 private final URI uri;
18 private final Type type;
19 private final String manufacturer;
20 private final String hwVersion;
21 private final String swVersion;
22 private final String serialNumber;
23
24 /**
25 * Creates a device description using the supplied information.
26 *
27 * @param uri device URI
28 * @param type device type
29 * @param manufacturer device manufacturer
30 * @param hwVersion device HW version
31 * @param swVersion device SW version
32 * @param serialNumber device serial number
tom27ae0e62014-10-01 20:35:01 -070033 * @param annotations optional key/value annotations map
tomd1900f32014-09-03 14:08:16 -070034 */
35 public DefaultDeviceDescription(URI uri, Type type, String manufacturer,
36 String hwVersion, String swVersion,
tom27ae0e62014-10-01 20:35:01 -070037 String serialNumber,
tomf5d85d42014-10-02 05:27:56 -070038 SparseAnnotations... annotations) {
tom27ae0e62014-10-01 20:35:01 -070039 super(annotations);
tomd1900f32014-09-03 14:08:16 -070040 this.uri = checkNotNull(uri, "Device URI cannot be null");
41 this.type = checkNotNull(type, "Device type cannot be null");
42 this.manufacturer = manufacturer;
43 this.hwVersion = hwVersion;
44 this.swVersion = swVersion;
45 this.serialNumber = serialNumber;
46 }
47
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070048 /**
49 * Creates a device description using the supplied information.
50 * @param base DeviceDescription to basic information
51 * @param annotations Annotations to use.
52 */
53 public DefaultDeviceDescription(DeviceDescription base,
54 SparseAnnotations... annotations) {
55 this(base.deviceURI(), base.type(), base.manufacturer(),
56 base.hwVersion(), base.swVersion(), base.serialNumber(),
57 annotations);
58 }
59
tomd1900f32014-09-03 14:08:16 -070060 @Override
61 public URI deviceURI() {
62 return uri;
63 }
64
65 @Override
66 public Type type() {
67 return type;
68 }
69
70 @Override
71 public String manufacturer() {
72 return manufacturer;
73 }
74
75 @Override
76 public String hwVersion() {
77 return hwVersion;
78 }
79
80 @Override
81 public String swVersion() {
82 return swVersion;
83 }
84
85 @Override
86 public String serialNumber() {
87 return serialNumber;
88 }
89
90 @Override
91 public String toString() {
92 return toStringHelper(this)
93 .add("uri", uri).add("type", type).add("mfr", manufacturer)
94 .add("hw", hwVersion).add("sw", swVersion)
95 .add("serial", serialNumber)
96 .toString();
97 }
98
Yuta HIGUCHIf1f1d322014-10-07 21:09:56 -070099 // default constructor for serialization
100 private DefaultDeviceDescription() {
101 this.uri = null;
102 this.type = null;
103 this.manufacturer = null;
104 this.hwVersion = null;
105 this.swVersion = null;
106 this.serialNumber = null;
107 }
tomd1900f32014-09-03 14:08:16 -0700108}