blob: 1207427264ea419ff76e57af6e412a888cda14c5 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
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 */
tom3065d122014-09-03 21:56:43 -070016package org.onlab.onos.net;
17
18import org.onlab.onos.net.provider.ProviderId;
alshabib7911a052014-10-16 17:49:37 -070019import org.onlab.packet.ChassisId;
tom3065d122014-09-03 21:56:43 -070020
21import java.util.Objects;
22
tomeadbb462014-09-07 16:10:19 -070023import static com.google.common.base.MoreObjects.toStringHelper;
tom3065d122014-09-03 21:56:43 -070024
25/**
tom4c6606f2014-09-07 11:11:21 -070026 * Default infrastructure device model implementation.
tom3065d122014-09-03 21:56:43 -070027 */
28public 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;
alshabib7911a052014-10-16 17:49:37 -070035 private final ChassisId chassisId;
tom3065d122014-09-03 21:56:43 -070036
tomc6491322014-09-19 15:27:40 -070037 // 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;
alshabib7911a052014-10-16 17:49:37 -070044 this.chassisId = null;
tomc6491322014-09-19 15:27:40 -070045 }
46
tom3065d122014-09-03 21:56:43 -070047 /**
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 HIGUCHI5c947272014-11-03 21:39:21 -080057 * @param chassisId chasis id
tomf5d85d42014-10-02 05:27:56 -070058 * @param annotations optional key/value annotations
tom3065d122014-09-03 21:56:43 -070059 */
60 public DefaultDevice(ProviderId providerId, DeviceId id, Type type,
61 String manufacturer, String hwVersion, String swVersion,
alshabib7911a052014-10-16 17:49:37 -070062 String serialNumber, ChassisId chassisId,
63 Annotations... annotations) {
tomf5d85d42014-10-02 05:27:56 -070064 super(providerId, id, annotations);
tom3065d122014-09-03 21:56:43 -070065 this.type = type;
66 this.manufacturer = manufacturer;
67 this.hwVersion = hwVersion;
68 this.swVersion = swVersion;
69 this.serialNumber = serialNumber;
alshabib7911a052014-10-16 17:49:37 -070070 this.chassisId = chassisId;
tom3065d122014-09-03 21:56:43 -070071 }
72
73 @Override
74 public DeviceId id() {
tom5a9383a2014-10-02 07:33:52 -070075 return (DeviceId) id;
tom3065d122014-09-03 21:56:43 -070076 }
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
alshabib7911a052014-10-16 17:49:37 -0700104 public ChassisId chassisId() {
105 return chassisId;
106 }
107
108 @Override
tom3065d122014-09-03 21:56:43 -0700109 public int hashCode() {
110 return Objects.hash(id, type, manufacturer, hwVersion, swVersion, serialNumber);
111 }
112
113 @Override
114 public boolean equals(Object obj) {
tomfc9a4ff2014-09-22 18:22:47 -0700115 if (this == obj) {
116 return true;
117 }
tom3065d122014-09-03 21:56:43 -0700118 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}