blob: 53f2676ac007be9d170ca33071e531184de102e1 [file] [log] [blame]
tom3065d122014-09-03 21:56:43 -07001package org.onlab.onos.net;
2
3import org.onlab.onos.net.provider.ProviderId;
alshabib7911a052014-10-16 17:49:37 -07004import org.onlab.packet.ChassisId;
tom3065d122014-09-03 21:56:43 -07005
6import java.util.Objects;
7
tomeadbb462014-09-07 16:10:19 -07008import static com.google.common.base.MoreObjects.toStringHelper;
tom3065d122014-09-03 21:56:43 -07009
10/**
tom4c6606f2014-09-07 11:11:21 -070011 * Default infrastructure device model implementation.
tom3065d122014-09-03 21:56:43 -070012 */
13public class DefaultDevice extends AbstractElement implements Device {
14
15 private final Type type;
16 private final String manufacturer;
17 private final String serialNumber;
18 private final String hwVersion;
19 private final String swVersion;
alshabib7911a052014-10-16 17:49:37 -070020 private final ChassisId chassisId;
tom3065d122014-09-03 21:56:43 -070021
tomc6491322014-09-19 15:27:40 -070022 // For serialization
23 private DefaultDevice() {
24 this.type = null;
25 this.manufacturer = null;
26 this.hwVersion = null;
27 this.swVersion = null;
28 this.serialNumber = null;
alshabib7911a052014-10-16 17:49:37 -070029 this.chassisId = null;
tomc6491322014-09-19 15:27:40 -070030 }
31
tom3065d122014-09-03 21:56:43 -070032 /**
33 * Creates a network element attributed to the specified provider.
34 *
35 * @param providerId identity of the provider
36 * @param id device identifier
37 * @param type device type
38 * @param manufacturer device manufacturer
39 * @param hwVersion device HW version
40 * @param swVersion device SW version
41 * @param serialNumber device serial number
tomf5d85d42014-10-02 05:27:56 -070042 * @param annotations optional key/value annotations
tom3065d122014-09-03 21:56:43 -070043 */
44 public DefaultDevice(ProviderId providerId, DeviceId id, Type type,
45 String manufacturer, String hwVersion, String swVersion,
alshabib7911a052014-10-16 17:49:37 -070046 String serialNumber, ChassisId chassisId,
47 Annotations... annotations) {
tomf5d85d42014-10-02 05:27:56 -070048 super(providerId, id, annotations);
tom3065d122014-09-03 21:56:43 -070049 this.type = type;
50 this.manufacturer = manufacturer;
51 this.hwVersion = hwVersion;
52 this.swVersion = swVersion;
53 this.serialNumber = serialNumber;
alshabib7911a052014-10-16 17:49:37 -070054 this.chassisId = chassisId;
tom3065d122014-09-03 21:56:43 -070055 }
56
57 @Override
58 public DeviceId id() {
tom5a9383a2014-10-02 07:33:52 -070059 return (DeviceId) id;
tom3065d122014-09-03 21:56:43 -070060 }
61
62 @Override
63 public Type type() {
64 return type;
65 }
66
67 @Override
68 public String manufacturer() {
69 return manufacturer;
70 }
71
72 @Override
73 public String hwVersion() {
74 return hwVersion;
75 }
76
77 @Override
78 public String swVersion() {
79 return swVersion;
80 }
81
82 @Override
83 public String serialNumber() {
84 return serialNumber;
85 }
86
87 @Override
alshabib7911a052014-10-16 17:49:37 -070088 public ChassisId chassisId() {
89 return chassisId;
90 }
91
92 @Override
tom3065d122014-09-03 21:56:43 -070093 public int hashCode() {
94 return Objects.hash(id, type, manufacturer, hwVersion, swVersion, serialNumber);
95 }
96
97 @Override
98 public boolean equals(Object obj) {
tomfc9a4ff2014-09-22 18:22:47 -070099 if (this == obj) {
100 return true;
101 }
tom3065d122014-09-03 21:56:43 -0700102 if (obj instanceof DefaultDevice) {
103 final DefaultDevice other = (DefaultDevice) obj;
104 return Objects.equals(this.id, other.id) &&
105 Objects.equals(this.type, other.type) &&
106 Objects.equals(this.manufacturer, other.manufacturer) &&
107 Objects.equals(this.hwVersion, other.hwVersion) &&
108 Objects.equals(this.swVersion, other.swVersion) &&
109 Objects.equals(this.serialNumber, other.serialNumber);
110 }
111 return false;
112 }
113
114 @Override
115 public String toString() {
116 return toStringHelper(this)
117 .add("id", id)
118 .add("type", type)
119 .add("manufacturer", manufacturer)
120 .add("hwVersion", hwVersion)
121 .add("swVersion", swVersion)
122 .add("serialNumber", serialNumber)
123 .toString();
124 }
125
126}