Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net; |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 17 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 18 | import org.onosproject.net.provider.ProviderId; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 19 | import org.onlab.packet.ChassisId; |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 20 | |
| 21 | import java.util.Objects; |
| 22 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 23 | import static com.google.common.base.MoreObjects.toStringHelper; |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 26 | * Default infrastructure device model implementation. |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 27 | */ |
| 28 | public class DefaultDevice extends AbstractElement implements Device { |
| 29 | |
| 30 | private final Type type; |
| 31 | private final String manufacturer; |
| 32 | private final String serialNumber; |
| 33 | private final String hwVersion; |
| 34 | private final String swVersion; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 35 | private final ChassisId chassisId; |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 36 | |
tom | c649132 | 2014-09-19 15:27:40 -0700 | [diff] [blame] | 37 | // For serialization |
| 38 | private DefaultDevice() { |
| 39 | this.type = null; |
| 40 | this.manufacturer = null; |
| 41 | this.hwVersion = null; |
| 42 | this.swVersion = null; |
| 43 | this.serialNumber = null; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 44 | this.chassisId = null; |
tom | c649132 | 2014-09-19 15:27:40 -0700 | [diff] [blame] | 45 | } |
| 46 | |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 47 | /** |
| 48 | * Creates a network element attributed to the specified provider. |
| 49 | * |
| 50 | * @param providerId identity of the provider |
| 51 | * @param id device identifier |
| 52 | * @param type device type |
| 53 | * @param manufacturer device manufacturer |
| 54 | * @param hwVersion device HW version |
| 55 | * @param swVersion device SW version |
| 56 | * @param serialNumber device serial number |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 57 | * @param chassisId chasis id |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 58 | * @param annotations optional key/value annotations |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 59 | */ |
| 60 | public DefaultDevice(ProviderId providerId, DeviceId id, Type type, |
| 61 | String manufacturer, String hwVersion, String swVersion, |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 62 | String serialNumber, ChassisId chassisId, |
| 63 | Annotations... annotations) { |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 64 | super(providerId, id, annotations); |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 65 | this.type = type; |
| 66 | this.manufacturer = manufacturer; |
| 67 | this.hwVersion = hwVersion; |
| 68 | this.swVersion = swVersion; |
| 69 | this.serialNumber = serialNumber; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 70 | this.chassisId = chassisId; |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public DeviceId id() { |
tom | 5a9383a | 2014-10-02 07:33:52 -0700 | [diff] [blame] | 75 | return (DeviceId) id; |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public Type type() { |
| 80 | return type; |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public String manufacturer() { |
| 85 | return manufacturer; |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public String hwVersion() { |
| 90 | return hwVersion; |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public String swVersion() { |
| 95 | return swVersion; |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public String serialNumber() { |
| 100 | return serialNumber; |
| 101 | } |
| 102 | |
| 103 | @Override |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 104 | public ChassisId chassisId() { |
| 105 | return chassisId; |
| 106 | } |
| 107 | |
| 108 | @Override |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 109 | public int hashCode() { |
| 110 | return Objects.hash(id, type, manufacturer, hwVersion, swVersion, serialNumber); |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public boolean equals(Object obj) { |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 115 | if (this == obj) { |
| 116 | return true; |
| 117 | } |
tom | 3065d12 | 2014-09-03 21:56:43 -0700 | [diff] [blame] | 118 | if (obj instanceof DefaultDevice) { |
| 119 | final DefaultDevice other = (DefaultDevice) obj; |
| 120 | return Objects.equals(this.id, other.id) && |
| 121 | Objects.equals(this.type, other.type) && |
| 122 | Objects.equals(this.manufacturer, other.manufacturer) && |
| 123 | Objects.equals(this.hwVersion, other.hwVersion) && |
| 124 | Objects.equals(this.swVersion, other.swVersion) && |
| 125 | Objects.equals(this.serialNumber, other.serialNumber); |
| 126 | } |
| 127 | return false; |
| 128 | } |
| 129 | |
| 130 | @Override |
| 131 | public String toString() { |
| 132 | return toStringHelper(this) |
| 133 | .add("id", id) |
| 134 | .add("type", type) |
| 135 | .add("manufacturer", manufacturer) |
| 136 | .add("hwVersion", hwVersion) |
| 137 | .add("swVersion", swVersion) |
| 138 | .add("serialNumber", serialNumber) |
| 139 | .toString(); |
| 140 | } |
| 141 | |
| 142 | } |