blob: 79710ae43981ad3e5b924a4cca8945cdb219b484 [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;
alshabib7911a052014-10-16 17:49:37 -07005import org.onlab.packet.ChassisId;
tom27ae0e62014-10-01 20:35:01 -07006
tomd1900f32014-09-03 14:08:16 -07007import java.net.URI;
8
tomeadbb462014-09-07 16:10:19 -07009import static com.google.common.base.MoreObjects.toStringHelper;
tomd1900f32014-09-03 14:08:16 -070010import static com.google.common.base.Preconditions.checkNotNull;
11import static org.onlab.onos.net.Device.Type;
12
13/**
14 * Default implementation of immutable device description entity.
15 */
tomf5d85d42014-10-02 05:27:56 -070016public class DefaultDeviceDescription extends AbstractDescription
tom27ae0e62014-10-01 20:35:01 -070017 implements DeviceDescription {
tomd1900f32014-09-03 14:08:16 -070018 private final URI uri;
19 private final Type type;
20 private final String manufacturer;
21 private final String hwVersion;
22 private final String swVersion;
23 private final String serialNumber;
alshabib7911a052014-10-16 17:49:37 -070024 private final ChassisId chassisId;
tomd1900f32014-09-03 14:08:16 -070025
26 /**
27 * Creates a device description using the supplied information.
28 *
29 * @param uri device URI
30 * @param type device type
31 * @param manufacturer device manufacturer
32 * @param hwVersion device HW version
33 * @param swVersion device SW version
34 * @param serialNumber device serial number
tom27ae0e62014-10-01 20:35:01 -070035 * @param annotations optional key/value annotations map
tomd1900f32014-09-03 14:08:16 -070036 */
37 public DefaultDeviceDescription(URI uri, Type type, String manufacturer,
38 String hwVersion, String swVersion,
alshabib7911a052014-10-16 17:49:37 -070039 String serialNumber, ChassisId chassis,
tomf5d85d42014-10-02 05:27:56 -070040 SparseAnnotations... annotations) {
tom27ae0e62014-10-01 20:35:01 -070041 super(annotations);
tomd1900f32014-09-03 14:08:16 -070042 this.uri = checkNotNull(uri, "Device URI cannot be null");
43 this.type = checkNotNull(type, "Device type cannot be null");
44 this.manufacturer = manufacturer;
45 this.hwVersion = hwVersion;
46 this.swVersion = swVersion;
47 this.serialNumber = serialNumber;
alshabib7911a052014-10-16 17:49:37 -070048 this.chassisId = chassis;
tomd1900f32014-09-03 14:08:16 -070049 }
50
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070051 /**
52 * Creates a device description using the supplied information.
53 * @param base DeviceDescription to basic information
54 * @param annotations Annotations to use.
55 */
56 public DefaultDeviceDescription(DeviceDescription base,
57 SparseAnnotations... annotations) {
58 this(base.deviceURI(), base.type(), base.manufacturer(),
59 base.hwVersion(), base.swVersion(), base.serialNumber(),
alshabib7911a052014-10-16 17:49:37 -070060 base.chassisId(), annotations);
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070061 }
62
tomd1900f32014-09-03 14:08:16 -070063 @Override
64 public URI deviceURI() {
65 return uri;
66 }
67
68 @Override
69 public Type type() {
70 return type;
71 }
72
73 @Override
74 public String manufacturer() {
75 return manufacturer;
76 }
77
78 @Override
79 public String hwVersion() {
80 return hwVersion;
81 }
82
83 @Override
84 public String swVersion() {
85 return swVersion;
86 }
87
88 @Override
89 public String serialNumber() {
90 return serialNumber;
91 }
92
93 @Override
alshabib7911a052014-10-16 17:49:37 -070094 public ChassisId chassisId() {
95 return chassisId;
96 }
97
98 @Override
tomd1900f32014-09-03 14:08:16 -070099 public String toString() {
100 return toStringHelper(this)
101 .add("uri", uri).add("type", type).add("mfr", manufacturer)
102 .add("hw", hwVersion).add("sw", swVersion)
103 .add("serial", serialNumber)
104 .toString();
105 }
106
Yuta HIGUCHIf1f1d322014-10-07 21:09:56 -0700107 // default constructor for serialization
108 private DefaultDeviceDescription() {
109 this.uri = null;
110 this.type = null;
111 this.manufacturer = null;
112 this.hwVersion = null;
113 this.swVersion = null;
114 this.serialNumber = null;
alshabib7911a052014-10-16 17:49:37 -0700115 this.chassisId = null;
Yuta HIGUCHIf1f1d322014-10-07 21:09:56 -0700116 }
tomd1900f32014-09-03 14:08:16 -0700117}