Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016 Open Networking Foundation |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -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 | package org.onosproject.tetopology.management.api.link; |
| 17 | |
| 18 | import org.onosproject.tetopology.management.api.TeTopologyKey; |
| 19 | import org.onosproject.tetopology.management.api.node.TeNodeKey; |
| 20 | |
| 21 | import com.google.common.base.MoreObjects.ToStringHelper; |
| 22 | import com.google.common.base.Objects; |
| 23 | |
| 24 | /** |
| 25 | * Representation of a global TE link TP (i.e., TE termination point) key. |
| 26 | */ |
| 27 | public class TeLinkTpGlobalKey extends TeNodeKey { |
| 28 | private final long teLinkTpId; |
| 29 | |
| 30 | /** |
| 31 | * Creates a global TE link TP key. |
| 32 | * |
| 33 | * @param providerId provider identifier |
| 34 | * @param clientId client identifier |
| 35 | * @param topologyId topology identifier |
| 36 | * @param teNodeId TE node identifier |
| 37 | * @param teLinkTpId TE link termination point identifier |
| 38 | */ |
| 39 | public TeLinkTpGlobalKey(long providerId, long clientId, |
| 40 | long topologyId, long teNodeId, |
| 41 | long teLinkTpId) { |
| 42 | super(providerId, clientId, topologyId, teNodeId); |
| 43 | this.teLinkTpId = teLinkTpId; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Creates a global TE link TP key based on a given local TE node key. |
| 48 | * |
| 49 | * @param teNodeKey the local TE node key |
| 50 | * @param teLinkTpId TE link termination point identifier |
| 51 | */ |
| 52 | public TeLinkTpGlobalKey(TeNodeKey teNodeKey, long teLinkTpId) { |
| 53 | super(teNodeKey.providerId(), teNodeKey.clientId(), |
| 54 | teNodeKey.topologyId(), teNodeKey.teNodeId()); |
| 55 | this.teLinkTpId = teLinkTpId; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Creates a global TE link TP key based on a given TE topology key |
| 60 | * and a local TE link TP key. |
| 61 | * |
| 62 | * @param teTopologyKey the key of TE Topology to which this link belongs |
| 63 | * @param teLinkTpKey the local TE link key |
| 64 | */ |
| 65 | public TeLinkTpGlobalKey(TeTopologyKey teTopologyKey, |
| 66 | TeLinkTpKey teLinkTpKey) { |
| 67 | super(teTopologyKey.providerId(), teTopologyKey.clientId(), |
| 68 | teTopologyKey.topologyId(), teLinkTpKey.teNodeId()); |
| 69 | this.teLinkTpId = teLinkTpKey.teLinkTpId(); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Returns the TE link TP identifier. |
| 74 | * |
| 75 | * @return the TE link id |
| 76 | */ |
| 77 | public long teLinkTpId() { |
| 78 | return teLinkTpId; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Returns the key of the TE node from which this link TP originates. |
| 83 | * |
| 84 | * @return the TE node key |
| 85 | */ |
| 86 | public TeNodeKey teNodeKey() { |
| 87 | return new TeNodeKey(providerId(), clientId(), topologyId(), teNodeId()); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Returns the key of the TE Topology to which this link TP belongs. |
| 92 | * |
| 93 | * @return the TE topology key |
| 94 | */ |
| 95 | @Override |
| 96 | public TeTopologyKey teTopologyKey() { |
| 97 | return new TeTopologyKey(providerId(), clientId(), topologyId()); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Returns the local TE link TP key. |
| 102 | * |
| 103 | * @return the TE link TP key |
| 104 | */ |
| 105 | public TeLinkTpKey teLinkTpKey() { |
| 106 | return new TeLinkTpKey(teNodeId(), teLinkTpId); |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public int hashCode() { |
| 111 | return Objects.hashCode(super.hashCode(), teLinkTpId); |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public boolean equals(Object object) { |
| 116 | if (this == object) { |
| 117 | return true; |
| 118 | } |
| 119 | if (object instanceof TeLinkTpGlobalKey) { |
| 120 | if (!super.equals(object)) { |
| 121 | return false; |
| 122 | } |
| 123 | TeLinkTpGlobalKey that = (TeLinkTpGlobalKey) object; |
| 124 | return Objects.equal(teLinkTpId, that.teLinkTpId); |
| 125 | } |
| 126 | return false; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Returns a helper for toString() with additional TE link TP identifier. |
| 131 | * |
| 132 | * @return a toString helper |
| 133 | */ |
| 134 | protected ToStringHelper toTeLinkTpKeyStringHelper() { |
| 135 | return toTeNodeKeyStringHelper().add("teLinkTpId", teLinkTpId); |
| 136 | } |
| 137 | |
| 138 | @Override |
| 139 | public String toString() { |
| 140 | return toTeLinkTpKeyStringHelper().toString(); |
| 141 | } |
| 142 | |
| 143 | } |