blob: 9d4f8a8d0490e2359c6ecb475063e275809b4369 [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 */
tom29df6f42014-09-05 08:14:14 -070016package org.onlab.onos.net;
17
Jonathan Hartb79d6412014-09-19 11:24:06 -070018import java.util.Objects;
Yuta HIGUCHI9827a352014-09-21 17:01:29 -070019
tomf5d85d42014-10-02 05:27:56 -070020import static com.google.common.base.MoreObjects.toStringHelper;
21
tom29df6f42014-09-05 08:14:14 -070022/**
23 * Default port implementation.
24 */
tom3ea11252014-10-02 04:32:26 -070025public class DefaultPort extends AbstractAnnotated implements Port {
tom29df6f42014-09-05 08:14:14 -070026
27 private final Element element;
28 private final PortNumber number;
29 private final boolean isEnabled;
30
Jonathan Hartb79d6412014-09-19 11:24:06 -070031 /**
32 * Creates a network element attributed to the specified provider.
33 *
34 * @param element parent network element
35 * @param number port number
36 * @param isEnabled indicator whether the port is up and active
tom3ea11252014-10-02 04:32:26 -070037 * @param annotations optional key/value annotations
Jonathan Hartb79d6412014-09-19 11:24:06 -070038 */
39 public DefaultPort(Element element, PortNumber number,
tomf5d85d42014-10-02 05:27:56 -070040 boolean isEnabled, Annotations... annotations) {
tom3ea11252014-10-02 04:32:26 -070041 super(annotations);
tom29df6f42014-09-05 08:14:14 -070042 this.element = element;
43 this.number = number;
44 this.isEnabled = isEnabled;
45 }
46
47 @Override
48 public int hashCode() {
49 return Objects.hash(number, isEnabled);
50 }
51
52 @Override
53 public boolean equals(Object obj) {
tomfc9a4ff2014-09-22 18:22:47 -070054 if (this == obj) {
55 return true;
56 }
tom29df6f42014-09-05 08:14:14 -070057 if (obj instanceof DefaultPort) {
58 final DefaultPort other = (DefaultPort) obj;
59 return Objects.equals(this.element.id(), other.element.id()) &&
60 Objects.equals(this.number, other.number) &&
61 Objects.equals(this.isEnabled, other.isEnabled);
62 }
63 return false;
64 }
65
66 @Override
67 public String toString() {
68 return toStringHelper(this)
69 .add("element", element.id())
70 .add("number", number)
71 .add("isEnabled", isEnabled)
72 .toString();
73 }
74
75 @Override
76 public PortNumber number() {
77 return number;
78 }
79
80 @Override
81 public boolean isEnabled() {
82 return isEnabled;
83 }
84
85 @Override
86 public Element element() {
87 return element;
88 }
89
tom29df6f42014-09-05 08:14:14 -070090}