Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016 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 | */ |
| 16 | |
| 17 | package org.onosproject.incubator.net.virtual; |
| 18 | |
| 19 | import org.onosproject.incubator.net.tunnel.TunnelId; |
| 20 | import org.onosproject.net.ConnectPoint; |
| 21 | import org.onosproject.net.DefaultAnnotations; |
| 22 | import org.onosproject.net.DefaultLink; |
| 23 | import org.onosproject.net.provider.ProviderId; |
| 24 | |
| 25 | import java.util.Objects; |
| 26 | |
| 27 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 28 | |
| 29 | /** |
| 30 | * Default representation of a virtual link. |
| 31 | */ |
| 32 | public final class DefaultVirtualLink extends DefaultLink implements VirtualLink { |
| 33 | |
| 34 | private static final String VIRTUAL = "virtual"; |
| 35 | private static final ProviderId PID = new ProviderId(VIRTUAL, VIRTUAL); |
| 36 | |
| 37 | private final NetworkId networkId; |
| 38 | private final TunnelId tunnelId; |
| 39 | |
| 40 | /** |
| 41 | * Constructor for a default virtual link. |
| 42 | * |
| 43 | * @param networkId network identifier |
| 44 | * @param src source connection point |
| 45 | * @param dst destination connection point |
| 46 | * @param tunnelId tunnel identifier |
| 47 | */ |
| 48 | public DefaultVirtualLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst, TunnelId tunnelId) { |
| 49 | super(PID, src, dst, Type.VIRTUAL, DefaultAnnotations.builder().build()); |
| 50 | this.networkId = networkId; |
| 51 | this.tunnelId = tunnelId; |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public NetworkId networkId() { |
| 56 | return networkId; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Returns the tunnel identifier. |
| 61 | * |
| 62 | * @return tunnel identifier. |
| 63 | */ |
| 64 | public TunnelId tunnelId() { |
| 65 | return tunnelId; |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public int hashCode() { |
| 70 | return Objects.hash(networkId, tunnelId); |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public boolean equals(Object obj) { |
| 75 | if (this == obj) { |
| 76 | return true; |
| 77 | } |
| 78 | if (obj instanceof DefaultVirtualLink) { |
| 79 | DefaultVirtualLink that = (DefaultVirtualLink) obj; |
| 80 | return super.equals(that) && |
| 81 | Objects.equals(this.networkId, that.networkId) && |
| 82 | Objects.equals(this.tunnelId, that.tunnelId); |
| 83 | } |
| 84 | return false; |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public String toString() { |
| 89 | return toStringHelper(this).add("networkId", networkId).add("tunnelId", tunnelId).toString(); |
| 90 | } |
| 91 | } |