Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
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 | |
| 19 | import org.onosproject.net.DefaultAnnotations; |
| 20 | import org.onosproject.net.DefaultPort; |
| 21 | import org.onosproject.net.Device; |
| 22 | import org.onosproject.net.Element; |
| 23 | import org.onosproject.net.Port; |
| 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 | |
| 35 | |
| 36 | private final NetworkId networkId; |
| 37 | private final Port realizedBy; |
| 38 | |
| 39 | public DefaultVirtualPort(NetworkId networkId, Device device, PortNumber portNumber, Port realizedBy) { |
| 40 | super((Element) device, portNumber, false, DefaultAnnotations.builder().build()); |
| 41 | this.networkId = networkId; |
| 42 | this.realizedBy = realizedBy; |
| 43 | } |
| 44 | |
| 45 | public NetworkId networkId() { |
| 46 | return networkId; |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public Port realizedBy() { |
| 51 | return realizedBy; |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public int hashCode() { |
| 56 | return Objects.hash(networkId, realizedBy); |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public boolean equals(Object obj) { |
| 61 | if (this == obj) { |
| 62 | return true; |
| 63 | } |
| 64 | if (obj instanceof DefaultVirtualPort) { |
| 65 | DefaultVirtualPort that = (DefaultVirtualPort) obj; |
| 66 | return super.equals(that) && |
| 67 | Objects.equals(this.networkId, that.networkId) && |
| 68 | Objects.equals(this.realizedBy, that.realizedBy); |
| 69 | } |
| 70 | return false; |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public String toString() { |
| 75 | return toStringHelper(this).add("networkId", networkId).add("realizedBy", realizedBy).toString(); |
| 76 | } |
| 77 | |
| 78 | } |