tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net; |
| 2 | |
| 3 | import org.onlab.onos.net.provider.ProviderId; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 4 | import org.onlab.packet.ChassisId; |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 5 | |
| 6 | import java.util.Objects; |
| 7 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 8 | import static com.google.common.base.MoreObjects.toStringHelper; |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 9 | |
| 10 | /** |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 11 | * Default infrastructure device model implementation. |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 12 | */ |
| 13 | public 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; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 20 | private final ChassisId chassisId; |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 21 | |
tom | c649132 | 2014-09-19 15:27:40 -0700 | [diff] [blame] | 22 | // 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; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 29 | this.chassisId = null; |
tom | c649132 | 2014-09-19 15:27:40 -0700 | [diff] [blame] | 30 | } |
| 31 | |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 32 | /** |
| 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 |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 42 | * @param annotations optional key/value annotations |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 43 | */ |
| 44 | public DefaultDevice(ProviderId providerId, DeviceId id, Type type, |
| 45 | String manufacturer, String hwVersion, String swVersion, |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 46 | String serialNumber, ChassisId chassisId, |
| 47 | Annotations... annotations) { |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 48 | super(providerId, id, annotations); |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 49 | this.type = type; |
| 50 | this.manufacturer = manufacturer; |
| 51 | this.hwVersion = hwVersion; |
| 52 | this.swVersion = swVersion; |
| 53 | this.serialNumber = serialNumber; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 54 | this.chassisId = chassisId; |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public DeviceId id() { |
tom | 5a9383a | 2014-10-02 07:33:52 -0700 | [diff] [blame] | 59 | return (DeviceId) id; |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 60 | } |
| 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 |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 88 | public ChassisId chassisId() { |
| 89 | return chassisId; |
| 90 | } |
| 91 | |
| 92 | @Override |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 93 | public int hashCode() { |
| 94 | return Objects.hash(id, type, manufacturer, hwVersion, swVersion, serialNumber); |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public boolean equals(Object obj) { |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 99 | if (this == obj) { |
| 100 | return true; |
| 101 | } |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 102 | 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 | } |