blob: 8b3eee1d92e45ed769204e85dddb84d88e46f2f7 [file] [log] [blame]
tom3065d122014-09-03 21:56:43 -07001package org.onlab.onos.net;
2
3import org.onlab.onos.net.provider.ProviderId;
4
5import java.util.Objects;
6
tomeadbb462014-09-07 16:10:19 -07007import static com.google.common.base.MoreObjects.toStringHelper;
tom3065d122014-09-03 21:56:43 -07008
9/**
tom4c6606f2014-09-07 11:11:21 -070010 * Default infrastructure device model implementation.
tom3065d122014-09-03 21:56:43 -070011 */
12public class DefaultDevice extends AbstractElement implements Device {
13
14 private final Type type;
15 private final String manufacturer;
16 private final String serialNumber;
17 private final String hwVersion;
18 private final String swVersion;
19
tomc6491322014-09-19 15:27:40 -070020 // For serialization
21 private DefaultDevice() {
22 this.type = null;
23 this.manufacturer = null;
24 this.hwVersion = null;
25 this.swVersion = null;
26 this.serialNumber = null;
27 }
28
tom3065d122014-09-03 21:56:43 -070029 /**
30 * Creates a network element attributed to the specified provider.
31 *
32 * @param providerId identity of the provider
33 * @param id device identifier
34 * @param type device type
35 * @param manufacturer device manufacturer
36 * @param hwVersion device HW version
37 * @param swVersion device SW version
38 * @param serialNumber device serial number
tomf5d85d42014-10-02 05:27:56 -070039 * @param annotations optional key/value annotations
tom3065d122014-09-03 21:56:43 -070040 */
41 public DefaultDevice(ProviderId providerId, DeviceId id, Type type,
42 String manufacturer, String hwVersion, String swVersion,
tomf5d85d42014-10-02 05:27:56 -070043 String serialNumber, Annotations... annotations) {
44 super(providerId, id, annotations);
tom3065d122014-09-03 21:56:43 -070045 this.type = type;
46 this.manufacturer = manufacturer;
47 this.hwVersion = hwVersion;
48 this.swVersion = swVersion;
49 this.serialNumber = serialNumber;
50 }
51
52 @Override
53 public DeviceId id() {
tom5a9383a2014-10-02 07:33:52 -070054 return (DeviceId) id;
tom3065d122014-09-03 21:56:43 -070055 }
56
57 @Override
58 public Type type() {
59 return type;
60 }
61
62 @Override
63 public String manufacturer() {
64 return manufacturer;
65 }
66
67 @Override
68 public String hwVersion() {
69 return hwVersion;
70 }
71
72 @Override
73 public String swVersion() {
74 return swVersion;
75 }
76
77 @Override
78 public String serialNumber() {
79 return serialNumber;
80 }
81
82 @Override
83 public int hashCode() {
84 return Objects.hash(id, type, manufacturer, hwVersion, swVersion, serialNumber);
85 }
86
87 @Override
88 public boolean equals(Object obj) {
tomfc9a4ff2014-09-22 18:22:47 -070089 if (this == obj) {
90 return true;
91 }
tom3065d122014-09-03 21:56:43 -070092 if (obj instanceof DefaultDevice) {
93 final DefaultDevice other = (DefaultDevice) obj;
94 return Objects.equals(this.id, other.id) &&
95 Objects.equals(this.type, other.type) &&
96 Objects.equals(this.manufacturer, other.manufacturer) &&
97 Objects.equals(this.hwVersion, other.hwVersion) &&
98 Objects.equals(this.swVersion, other.swVersion) &&
99 Objects.equals(this.serialNumber, other.serialNumber);
100 }
101 return false;
102 }
103
104 @Override
105 public String toString() {
106 return toStringHelper(this)
107 .add("id", id)
108 .add("type", type)
109 .add("manufacturer", manufacturer)
110 .add("hwVersion", hwVersion)
111 .add("swVersion", swVersion)
112 .add("serialNumber", serialNumber)
113 .toString();
114 }
115
116}