blob: 56bca4539f162b457ac898fa56379a5661aa1552 [file] [log] [blame]
Madan Jampanic27b6b22016-02-05 11:36:31 -08001/*
2 * Copyright 2015 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 */
16package org.onosproject.iptopology.api;
17
18import org.onosproject.net.AbstractElement;
19import org.onosproject.net.Annotations;
20import org.onosproject.net.DeviceId;
21import org.onosproject.net.provider.ProviderId;
22
23import java.util.Objects;
24
25import static com.google.common.base.MoreObjects.toStringHelper;
26
27/**
28 * Default ip device model implementation.
29 */
30public class DefaultIpDevice extends AbstractElement implements IpDevice {
31
32 private final Type type;
33 private final IpDeviceIdentifier deviceIdentifier;
34 private final DeviceTed deviceTed;
35
36
37 /**
38 * For Serialization.
39 */
40 private DefaultIpDevice() {
41 this.type = null;
42 this.deviceIdentifier = null;
43 this.deviceTed = null;
44 }
45
46 /**
47 * Creates a network element attributed to the specified provider.
48 *
49 * @param providerId identity of the provider
50 * @param id device identifier
51 * @param type device type
52 * @param deviceIdentifier provides device identifier details
53 * @param deviceTed device traffic engineering parameters
54 * @param annotations optional key/value annotations
55 */
56 public DefaultIpDevice(ProviderId providerId, DeviceId id, Type type,
57 IpDeviceIdentifier deviceIdentifier, DeviceTed deviceTed,
58 Annotations... annotations) {
59 super(providerId, id, annotations);
60 this.type = type;
61 this.deviceIdentifier = deviceIdentifier;
62 this.deviceTed = deviceTed;
63 }
64
65 @Override
66 public DeviceId id() {
67 return (DeviceId) id;
68 }
69
70 @Override
71 public Type type() {
72 return type;
73 }
74
75 @Override
76 public IpDeviceIdentifier deviceIdentifier() {
77 return deviceIdentifier;
78 }
79
80 @Override
81 public DeviceTed deviceTed() {
82 return deviceTed; }
83
84 @Override
85 public int hashCode() {
86 return Objects.hash(type, deviceIdentifier, deviceTed);
87 }
88
89 @Override
90 public boolean equals(Object obj) {
91 if (this == obj) {
92 return true;
93 }
94
95 if (obj instanceof DefaultIpDevice) {
96 final DefaultIpDevice other = (DefaultIpDevice) obj;
97 return Objects.equals(this.id, other.id) &&
98 Objects.equals(this.type, other.type) &&
99 Objects.equals(this.deviceIdentifier, other.deviceIdentifier) &&
100 Objects.equals(this.deviceTed, other.deviceTed);
101 }
102 return false;
103 }
104 @Override
105 public String toString() {
106 return toStringHelper(this)
107 .omitNullValues()
108 .add("id", id)
109 .add("deviceIdentifier", deviceIdentifier)
110 .add("deviceTed", deviceTed)
111 .toString();
112 }
Satish Kf6d87cb2015-11-30 19:59:22 +0530113}