Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net; |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 17 | |
Jonathan Hart | b79d641 | 2014-09-19 11:24:06 -0700 | [diff] [blame] | 18 | import java.util.Objects; |
Yuta HIGUCHI | 9827a35 | 2014-09-21 17:01:29 -0700 | [diff] [blame] | 19 | |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 20 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 21 | |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 22 | /** |
| 23 | * Default port implementation. |
| 24 | */ |
tom | 3ea1125 | 2014-10-02 04:32:26 -0700 | [diff] [blame] | 25 | public class DefaultPort extends AbstractAnnotated implements Port { |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 26 | |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 27 | /** Default port speed in Mbps. */ |
| 28 | public static final long DEFAULT_SPEED = 1_000; |
| 29 | |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 30 | private final Element element; |
| 31 | private final PortNumber number; |
| 32 | private final boolean isEnabled; |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 33 | private final Type type; |
| 34 | private final long portSpeed; |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 35 | |
Jonathan Hart | b79d641 | 2014-09-19 11:24:06 -0700 | [diff] [blame] | 36 | /** |
| 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 |
tom | 3ea1125 | 2014-10-02 04:32:26 -0700 | [diff] [blame] | 42 | * @param annotations optional key/value annotations |
Jonathan Hart | b79d641 | 2014-09-19 11:24:06 -0700 | [diff] [blame] | 43 | */ |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 44 | 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) { |
tom | 3ea1125 | 2014-10-02 04:32:26 -0700 | [diff] [blame] | 61 | super(annotations); |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 62 | this.element = element; |
| 63 | this.number = number; |
| 64 | this.isEnabled = isEnabled; |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 65 | this.type = type; |
| 66 | this.portSpeed = portSpeed; |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | @Override |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 70 | public Element element() { |
| 71 | return element; |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 72 | } |
| 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 Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 85 | 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 Leenheer | bb38235 | 2015-04-23 18:20:34 -0700 | [diff] [blame] | 96 | return Objects.hash(number, isEnabled, type, portSpeed, annotations()); |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 97 | } |
| 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 Leenheer | bb38235 | 2015-04-23 18:20:34 -0700 | [diff] [blame] | 110 | Objects.equals(this.portSpeed, other.portSpeed) && |
| 111 | Objects.equals(this.annotations(), other.annotations()); |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 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) |
Yuta HIGUCHI | 22ba76d | 2016-11-11 16:56:24 -0800 | [diff] [blame] | 124 | .add("annotations", annotations()) |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 125 | .toString(); |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 126 | } |
| 127 | |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 128 | } |