tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.device; |
| 2 | |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 3 | import org.onlab.onos.net.AbstractDescription; |
| 4 | import org.onlab.onos.net.SparseAnnotations; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 5 | import org.onlab.packet.ChassisId; |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 6 | |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 7 | import java.net.URI; |
| 8 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 9 | import static com.google.common.base.MoreObjects.toStringHelper; |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 10 | import static com.google.common.base.Preconditions.checkNotNull; |
| 11 | import static org.onlab.onos.net.Device.Type; |
| 12 | |
| 13 | /** |
| 14 | * Default implementation of immutable device description entity. |
| 15 | */ |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 16 | public class DefaultDeviceDescription extends AbstractDescription |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 17 | implements DeviceDescription { |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 18 | 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; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 24 | private final ChassisId chassisId; |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 25 | |
| 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 |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 35 | * @param annotations optional key/value annotations map |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 36 | */ |
| 37 | public DefaultDeviceDescription(URI uri, Type type, String manufacturer, |
| 38 | String hwVersion, String swVersion, |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 39 | String serialNumber, ChassisId chassis, |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 40 | SparseAnnotations... annotations) { |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 41 | super(annotations); |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 42 | 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; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 48 | this.chassisId = chassis; |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Yuta HIGUCHI | 55710e7 | 2014-10-02 14:58:32 -0700 | [diff] [blame] | 51 | /** |
| 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(), |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 60 | base.chassisId(), annotations); |
Yuta HIGUCHI | 55710e7 | 2014-10-02 14:58:32 -0700 | [diff] [blame] | 61 | } |
| 62 | |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 63 | @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 |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 94 | public ChassisId chassisId() { |
| 95 | return chassisId; |
| 96 | } |
| 97 | |
| 98 | @Override |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 99 | 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 HIGUCHI | f1f1d32 | 2014-10-07 21:09:56 -0700 | [diff] [blame] | 107 | // 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; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 115 | this.chassisId = null; |
Yuta HIGUCHI | f1f1d32 | 2014-10-07 21:09:56 -0700 | [diff] [blame] | 116 | } |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 117 | } |