blob: 70023cce56cab2feebb2e352b89fe69cf4c15a84 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net;
tom29df6f42014-09-05 08:14:14 -070017
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
Thomas Vachuskad16ce182014-10-29 17:25:29 -070027 /** Default port speed in Mbps. */
28 public static final long DEFAULT_SPEED = 1_000;
29
tom29df6f42014-09-05 08:14:14 -070030 private final Element element;
31 private final PortNumber number;
32 private final boolean isEnabled;
Thomas Vachuskad16ce182014-10-29 17:25:29 -070033 private final Type type;
34 private final long portSpeed;
tom29df6f42014-09-05 08:14:14 -070035
Jonathan Hartb79d6412014-09-19 11:24:06 -070036 /**
37 * Creates a network element attributed to the specified provider.
38 *
39 * @param element parent network element
40 * @param number port number
41 * @param isEnabled indicator whether the port is up and active
tom3ea11252014-10-02 04:32:26 -070042 * @param annotations optional key/value annotations
Jonathan Hartb79d6412014-09-19 11:24:06 -070043 */
Thomas Vachuskad16ce182014-10-29 17:25:29 -070044 public DefaultPort(Element element, PortNumber number, boolean isEnabled,
45 Annotations... annotations) {
46 this(element, number, isEnabled, Type.COPPER, DEFAULT_SPEED, annotations);
47 }
48
49 /**
50 * Creates a network element attributed to the specified provider.
51 *
52 * @param element parent network element
53 * @param number port number
54 * @param isEnabled indicator whether the port is up and active
55 * @param type port type
56 * @param portSpeed port speed in Mbs
57 * @param annotations optional key/value annotations
58 */
59 public DefaultPort(Element element, PortNumber number, boolean isEnabled,
60 Type type, long portSpeed, Annotations... annotations) {
tom3ea11252014-10-02 04:32:26 -070061 super(annotations);
tom29df6f42014-09-05 08:14:14 -070062 this.element = element;
63 this.number = number;
64 this.isEnabled = isEnabled;
Thomas Vachuskad16ce182014-10-29 17:25:29 -070065 this.type = type;
66 this.portSpeed = portSpeed;
tom29df6f42014-09-05 08:14:14 -070067 }
68
69 @Override
Thomas Vachuskad16ce182014-10-29 17:25:29 -070070 public Element element() {
71 return element;
tom29df6f42014-09-05 08:14:14 -070072 }
73
74 @Override
75 public PortNumber number() {
76 return number;
77 }
78
79 @Override
80 public boolean isEnabled() {
81 return isEnabled;
82 }
83
84 @Override
Thomas Vachuskad16ce182014-10-29 17:25:29 -070085 public Type type() {
86 return type;
87 }
88
89 @Override
90 public long portSpeed() {
91 return portSpeed;
92 }
93
94 @Override
95 public int hashCode() {
Marc De Leenheerbb382352015-04-23 18:20:34 -070096 return Objects.hash(number, isEnabled, type, portSpeed, annotations());
Thomas Vachuskad16ce182014-10-29 17:25:29 -070097 }
98
99 @Override
100 public boolean equals(Object obj) {
101 if (this == obj) {
102 return true;
103 }
104 if (obj instanceof DefaultPort) {
105 final DefaultPort other = (DefaultPort) obj;
106 return Objects.equals(this.element.id(), other.element.id()) &&
107 Objects.equals(this.number, other.number) &&
108 Objects.equals(this.isEnabled, other.isEnabled) &&
109 Objects.equals(this.type, other.type) &&
Marc De Leenheerbb382352015-04-23 18:20:34 -0700110 Objects.equals(this.portSpeed, other.portSpeed) &&
111 Objects.equals(this.annotations(), other.annotations());
Thomas Vachuskad16ce182014-10-29 17:25:29 -0700112 }
113 return false;
114 }
115
116 @Override
117 public String toString() {
118 return toStringHelper(this)
119 .add("element", element.id())
120 .add("number", number)
121 .add("isEnabled", isEnabled)
122 .add("type", type)
123 .add("portSpeed", portSpeed)
Yuta HIGUCHI22ba76d2016-11-11 16:56:24 -0800124 .add("annotations", annotations())
Thomas Vachuskad16ce182014-10-29 17:25:29 -0700125 .toString();
tom29df6f42014-09-05 08:14:14 -0700126 }
127
tom29df6f42014-09-05 08:14:14 -0700128}