blob: f6ba352a128e1fd407634ab53713bc37d25466f9 [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
tomf5d85d42014-10-02 05:27:56 -070057 * @param annotations optional key/value annotations
tom3065d122014-09-03 21:56:43 -070058 */
59 public DefaultDevice(ProviderId providerId, DeviceId id, Type type,
60 String manufacturer, String hwVersion, String swVersion,
alshabib7911a052014-10-16 17:49:37 -070061 String serialNumber, ChassisId chassisId,
62 Annotations... annotations) {
tomf5d85d42014-10-02 05:27:56 -070063 super(providerId, id, annotations);
tom3065d122014-09-03 21:56:43 -070064 this.type = type;
65 this.manufacturer = manufacturer;
66 this.hwVersion = hwVersion;
67 this.swVersion = swVersion;
68 this.serialNumber = serialNumber;
alshabib7911a052014-10-16 17:49:37 -070069 this.chassisId = chassisId;
tom3065d122014-09-03 21:56:43 -070070 }
71
72 @Override
73 public DeviceId id() {
tom5a9383a2014-10-02 07:33:52 -070074 return (DeviceId) id;
tom3065d122014-09-03 21:56:43 -070075 }
76
77 @Override
78 public Type type() {
79 return type;
80 }
81
82 @Override
83 public String manufacturer() {
84 return manufacturer;
85 }
86
87 @Override
88 public String hwVersion() {
89 return hwVersion;
90 }
91
92 @Override
93 public String swVersion() {
94 return swVersion;
95 }
96
97 @Override
98 public String serialNumber() {
99 return serialNumber;
100 }
101
102 @Override
alshabib7911a052014-10-16 17:49:37 -0700103 public ChassisId chassisId() {
104 return chassisId;
105 }
106
107 @Override
tom3065d122014-09-03 21:56:43 -0700108 public int hashCode() {
109 return Objects.hash(id, type, manufacturer, hwVersion, swVersion, serialNumber);
110 }
111
112 @Override
113 public boolean equals(Object obj) {
tomfc9a4ff2014-09-22 18:22:47 -0700114 if (this == obj) {
115 return true;
116 }
tom3065d122014-09-03 21:56:43 -0700117 if (obj instanceof DefaultDevice) {
118 final DefaultDevice other = (DefaultDevice) obj;
119 return Objects.equals(this.id, other.id) &&
120 Objects.equals(this.type, other.type) &&
121 Objects.equals(this.manufacturer, other.manufacturer) &&
122 Objects.equals(this.hwVersion, other.hwVersion) &&
123 Objects.equals(this.swVersion, other.swVersion) &&
124 Objects.equals(this.serialNumber, other.serialNumber);
125 }
126 return false;
127 }
128
129 @Override
130 public String toString() {
131 return toStringHelper(this)
132 .add("id", id)
133 .add("type", type)
134 .add("manufacturer", manufacturer)
135 .add("hwVersion", hwVersion)
136 .add("swVersion", swVersion)
137 .add("serialNumber", serialNumber)
138 .toString();
139 }
140
141}