tony-liu | aff59a7 | 2016-10-21 15:41:46 +0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
tony-liu | aff59a7 | 2016-10-21 15:41:46 +0800 | [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.tetunnel.api.tunnel; |
| 18 | |
| 19 | import com.google.common.base.Objects; |
| 20 | import org.onosproject.tetopology.management.api.TeTopologyKey; |
| 21 | |
| 22 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 23 | |
| 24 | /** |
| 25 | * Representation of a TE tunnel key, which identifies a TE tunnel globally. |
| 26 | */ |
| 27 | public class TeTunnelKey extends TeTopologyKey { |
| 28 | |
| 29 | private final long teTunnelId; |
| 30 | |
| 31 | /** |
| 32 | * Creates an instance of TE tunnel key with supplied information. |
| 33 | * |
| 34 | * @param providerId provider identifier |
| 35 | * @param clientId client identifier |
| 36 | * @param topologyId topology identifier |
| 37 | * @param teTunnelId TE tunnel identifier |
| 38 | */ |
| 39 | public TeTunnelKey(long providerId, long clientId, |
| 40 | long topologyId, long teTunnelId) { |
| 41 | super(providerId, clientId, topologyId); |
| 42 | this.teTunnelId = teTunnelId; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Creates an instance of TE tunnel key with specified TeTopologyKey and |
| 47 | * supplied TE tunnel identifier. |
| 48 | * |
| 49 | * @param key the key of TE topology to which this tunnel belongs |
| 50 | * @param tunnelId TE tunnel identifier |
| 51 | */ |
| 52 | public TeTunnelKey(TeTopologyKey key, long tunnelId) { |
| 53 | super(key.providerId(), key.clientId(), key.topologyId()); |
| 54 | this.teTunnelId = tunnelId; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Returns the TE tunnel identifier. |
| 59 | * |
| 60 | * @return TE tunnel identifier |
| 61 | */ |
| 62 | public long teTunnelId() { |
| 63 | return teTunnelId; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Returns key of the TE topology to which this tunnel belongs. |
| 68 | * |
| 69 | * @return corresponding TE topology key |
| 70 | */ |
| 71 | public TeTopologyKey teTopologyKey() { |
| 72 | return new TeTopologyKey(providerId(), clientId(), topologyId()); |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public int hashCode() { |
| 77 | return Objects.hashCode(super.hashCode(), teTunnelId); |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public boolean equals(Object object) { |
| 82 | if (this == object) { |
| 83 | return true; |
| 84 | } |
| 85 | if (object instanceof TeTunnelKey) { |
| 86 | if (!super.equals(object)) { |
| 87 | return false; |
| 88 | } |
| 89 | TeTunnelKey that = (TeTunnelKey) object; |
| 90 | return Objects.equal(this.teTunnelId, that.teTunnelId); |
| 91 | } |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public String toString() { |
| 97 | return toStringHelper() |
| 98 | .add("topologyId", topologyId()) |
| 99 | .add("teTunnelId", teTunnelId) |
| 100 | .toString(); |
| 101 | } |
| 102 | } |
| 103 | |