blob: d9cd76483e773c629fce7b5fc218bf0aeee48d82 [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
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;
67
tom29df6f42014-09-05 08:14:14 -070068 }
69
70 @Override
Thomas Vachuskad16ce182014-10-29 17:25:29 -070071 public Element element() {
72 return element;
tom29df6f42014-09-05 08:14:14 -070073 }
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
Thomas Vachuskad16ce182014-10-29 17:25:29 -070086 public Type type() {
87 return type;
88 }
89
90 @Override
91 public long portSpeed() {
92 return portSpeed;
93 }
94
95 @Override
96 public int hashCode() {
97 return Objects.hash(number, isEnabled, type, portSpeed);
98 }
99
100 @Override
101 public boolean equals(Object obj) {
102 if (this == obj) {
103 return true;
104 }
105 if (obj instanceof DefaultPort) {
106 final DefaultPort other = (DefaultPort) obj;
107 return Objects.equals(this.element.id(), other.element.id()) &&
108 Objects.equals(this.number, other.number) &&
109 Objects.equals(this.isEnabled, other.isEnabled) &&
110 Objects.equals(this.type, other.type) &&
111 Objects.equals(this.portSpeed, other.portSpeed);
112 }
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)
124 .toString();
tom29df6f42014-09-05 08:14:14 -0700125 }
126
tom29df6f42014-09-05 08:14:14 -0700127}