Yixiao Chen | 68bfab2 | 2016-11-11 11:04:10 -0500 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Yixiao Chen | 68bfab2 | 2016-11-11 11:04:10 -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.impl; |
| 17 | |
| 18 | import org.onosproject.tetopology.management.api.TeTopologyKey; |
| 19 | import org.onosproject.tetopology.management.api.link.CommonLinkData; |
| 20 | import org.onosproject.tetopology.management.api.link.NetworkLinkKey; |
| 21 | import org.onosproject.tetopology.management.api.link.TeLink; |
| 22 | import org.onosproject.tetopology.management.api.link.TeLinkTpGlobalKey; |
| 23 | import org.onosproject.tetopology.management.api.link.TeLinkTpKey; |
| 24 | |
| 25 | import com.google.common.base.MoreObjects; |
| 26 | import com.google.common.base.Objects; |
| 27 | |
| 28 | /** |
| 29 | * The TE link representation in store. |
| 30 | */ |
| 31 | public class InternalTeLink { |
| 32 | private TeLinkTpKey peerTeLinkKey; |
| 33 | private TeTopologyKey underlayTopologyKey; |
| 34 | private TeLinkTpGlobalKey supportingLinkKey; |
| 35 | private TeLinkTpGlobalKey sourceTeLinkKey; |
| 36 | private CommonLinkData teData; |
| 37 | private NetworkLinkKey networkLinkKey; |
| 38 | private boolean parentUpdate; |
| 39 | |
| 40 | /** |
| 41 | * Creates an instance of InternalLink. |
| 42 | * |
| 43 | * @param link the TE link |
| 44 | * @param parentUpdate indicator the TE node is updated by parent |
| 45 | */ |
| 46 | public InternalTeLink(TeLink link, boolean parentUpdate) { |
| 47 | this.parentUpdate = parentUpdate; |
| 48 | // Peer link key |
| 49 | this.peerTeLinkKey = link.peerTeLinkKey(); |
| 50 | // Underlay topology |
| 51 | this.underlayTopologyKey = link.underlayTeTopologyId(); |
| 52 | // Supporting topology |
| 53 | this.supportingLinkKey = link.supportingTeLinkId(); |
| 54 | // Source topology |
| 55 | this.sourceTeLinkKey = link.sourceTeLinkId(); |
| 56 | // Common data |
| 57 | this.teData = new CommonLinkData(link); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Returns the bi-directional peer link key. |
| 62 | * |
| 63 | * @return the peerTeLinkKey |
| 64 | */ |
| 65 | public TeLinkTpKey peerTeLinkKey() { |
| 66 | return peerTeLinkKey; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Sets the bi-directional peer link key. |
| 71 | * |
| 72 | * @param peerTeLinkKey the peerTeLinkKey to set |
| 73 | */ |
| 74 | public void setPeerTeLinkKey(TeLinkTpKey peerTeLinkKey) { |
| 75 | this.peerTeLinkKey = peerTeLinkKey; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Returns the link underlay topology key. |
| 80 | * |
| 81 | * @return the underlayTopologyKey |
| 82 | */ |
| 83 | public TeTopologyKey underlayTopologyKey() { |
| 84 | return underlayTopologyKey; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Sets the link underlay topology key. |
| 89 | * |
| 90 | * @param underlayTopologyKey the underlayTopologyKey to set |
| 91 | */ |
| 92 | public void setUnderlayTopologyKey(TeTopologyKey underlayTopologyKey) { |
| 93 | this.underlayTopologyKey = underlayTopologyKey; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Returns the supporting link key. |
| 98 | * |
| 99 | * @return the supportingLinkKey |
| 100 | */ |
| 101 | public TeLinkTpGlobalKey supportingLinkKey() { |
| 102 | return supportingLinkKey; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Sets the supporting link key. |
| 107 | * |
| 108 | * @param supportingLinkKey the supportingLinkKey to set |
| 109 | */ |
| 110 | public void setSupportingLinkKey(TeLinkTpGlobalKey supportingLinkKey) { |
| 111 | this.supportingLinkKey = supportingLinkKey; |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Returns the source link key. |
| 116 | * |
| 117 | * @return the sourceTeLinkKey |
| 118 | */ |
| 119 | public TeLinkTpGlobalKey sourceTeLinkKey() { |
| 120 | return sourceTeLinkKey; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Sets the source link key. |
| 125 | * |
| 126 | * @param sourceTeLinkKey the sourceTeLinkKey to set |
| 127 | */ |
| 128 | public void setSourceTeNodeKey(TeLinkTpGlobalKey sourceTeLinkKey) { |
| 129 | this.sourceTeLinkKey = sourceTeLinkKey; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Returns the link common data. |
| 134 | * |
| 135 | * @return the teData |
| 136 | */ |
| 137 | public CommonLinkData teData() { |
| 138 | return teData; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Sets the link common data. |
| 143 | * |
| 144 | * @param teData the teData to set |
| 145 | */ |
| 146 | public void setTeData(CommonLinkData teData) { |
| 147 | this.teData = teData; |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Sets the network link key. |
| 152 | * |
| 153 | * @param networkLinkKey the networkLinkKey to set |
| 154 | */ |
| 155 | public void setNetworkLinkKey(NetworkLinkKey networkLinkKey) { |
| 156 | this.networkLinkKey = networkLinkKey; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Returns the network link key. |
| 161 | * |
| 162 | * @return the networkLinkKey |
| 163 | */ |
| 164 | public NetworkLinkKey networkLinkKey() { |
| 165 | return networkLinkKey; |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Returns the indicator if the data was updated by parent. |
| 170 | * |
| 171 | * @return value of parentUpdate |
| 172 | */ |
| 173 | public boolean parentUpdate() { |
| 174 | return parentUpdate; |
| 175 | } |
| 176 | |
| 177 | @Override |
| 178 | public int hashCode() { |
| 179 | return Objects.hashCode(peerTeLinkKey, underlayTopologyKey, |
| 180 | supportingLinkKey, sourceTeLinkKey, teData, networkLinkKey); |
| 181 | } |
| 182 | |
| 183 | @Override |
| 184 | public boolean equals(Object object) { |
| 185 | if (this == object) { |
| 186 | return true; |
| 187 | } |
| 188 | if (object instanceof InternalTeLink) { |
| 189 | InternalTeLink that = (InternalTeLink) object; |
| 190 | return Objects.equal(peerTeLinkKey, that.peerTeLinkKey) |
| 191 | && Objects.equal(underlayTopologyKey, |
| 192 | that.underlayTopologyKey) |
| 193 | && Objects.equal(supportingLinkKey, that.supportingLinkKey) |
| 194 | && Objects.equal(sourceTeLinkKey, that.sourceTeLinkKey) |
| 195 | && Objects.equal(networkLinkKey, that.networkLinkKey) |
| 196 | && Objects.equal(teData, that.teData); |
| 197 | } |
| 198 | return false; |
| 199 | } |
| 200 | |
| 201 | @Override |
| 202 | public String toString() { |
| 203 | return MoreObjects.toStringHelper(this) |
| 204 | .add("peerTeLinkKey", peerTeLinkKey) |
| 205 | .add("underlayTopologyKey", underlayTopologyKey) |
| 206 | .add("supportingLinkKey", supportingLinkKey) |
| 207 | .add("sourceTeLinkKey", sourceTeLinkKey) |
| 208 | .add("teData", teData) |
| 209 | .add("networkLinkKey", networkLinkKey) |
| 210 | .add("parentUpdate", parentUpdate) |
| 211 | .toString(); |
| 212 | } |
| 213 | } |