Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [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 | */ |
| 16 | |
| 17 | package org.onosproject.incubator.net.virtual; |
| 18 | |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 19 | import org.onosproject.net.ConnectPoint; |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 20 | import org.onosproject.net.DefaultAnnotations; |
| 21 | import org.onosproject.net.DefaultPort; |
| 22 | import org.onosproject.net.Device; |
| 23 | import org.onosproject.net.Element; |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 24 | import org.onosproject.net.PortNumber; |
| 25 | |
| 26 | import java.util.Objects; |
| 27 | |
| 28 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 29 | |
| 30 | /** |
| 31 | * Default representation of a virtual port. |
| 32 | */ |
| 33 | public final class DefaultVirtualPort extends DefaultPort implements VirtualPort { |
| 34 | |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 35 | private final NetworkId networkId; |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 36 | private final ConnectPoint realizedBy; |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 37 | |
Claudine Chiu | 579969d | 2017-10-06 14:32:18 -0400 | [diff] [blame^] | 38 | /** |
| 39 | * Creates a virtual port. |
| 40 | * |
| 41 | * @param networkId network identifier |
| 42 | * @param device parent network element |
| 43 | * @param portNumber port number |
| 44 | * @param realizedBy underling port which realizes this virtual port |
| 45 | */ |
| 46 | public DefaultVirtualPort(NetworkId networkId, Device device, PortNumber portNumber, |
| 47 | ConnectPoint realizedBy) { |
| 48 | this(networkId, device, portNumber, false, realizedBy); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Creates a virtual port. |
| 53 | * |
| 54 | * @param networkId network identifier |
| 55 | * @param device parent network element |
| 56 | * @param portNumber port number |
| 57 | * @param isEnabled indicator whether the port is up and active |
| 58 | * @param realizedBy underling port which realizes this virtual port |
| 59 | */ |
| 60 | public DefaultVirtualPort(NetworkId networkId, Device device, PortNumber portNumber, |
| 61 | boolean isEnabled, ConnectPoint realizedBy) { |
| 62 | super((Element) device, portNumber, isEnabled, DefaultAnnotations.builder().build()); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 63 | this.networkId = networkId; |
| 64 | this.realizedBy = realizedBy; |
| 65 | } |
| 66 | |
Claudine Chiu | 579969d | 2017-10-06 14:32:18 -0400 | [diff] [blame^] | 67 | /** |
| 68 | * Returns network identifier. |
| 69 | * |
| 70 | * @return network identifier |
| 71 | */ |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 72 | public NetworkId networkId() { |
| 73 | return networkId; |
| 74 | } |
| 75 | |
| 76 | @Override |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 77 | public ConnectPoint realizedBy() { |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 78 | return realizedBy; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public int hashCode() { |
| 83 | return Objects.hash(networkId, realizedBy); |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public boolean equals(Object obj) { |
| 88 | if (this == obj) { |
| 89 | return true; |
| 90 | } |
| 91 | if (obj instanceof DefaultVirtualPort) { |
| 92 | DefaultVirtualPort that = (DefaultVirtualPort) obj; |
| 93 | return super.equals(that) && |
| 94 | Objects.equals(this.networkId, that.networkId) && |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 95 | Objects.equals(this.number(), that.number()) && |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 96 | Objects.equals(this.realizedBy, that.realizedBy); |
| 97 | } |
| 98 | return false; |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public String toString() { |
| 103 | return toStringHelper(this).add("networkId", networkId).add("realizedBy", realizedBy).toString(); |
| 104 | } |
| 105 | |
| 106 | } |