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 static org.onosproject.tetopology.management.api.TeConstants.NIL_LONG_VALUE; |
| 19 | |
| 20 | import java.util.List; |
| 21 | import java.util.Map; |
| 22 | |
| 23 | import org.apache.commons.collections.MapUtils; |
| 24 | import org.onosproject.tetopology.management.api.CommonTopologyData; |
| 25 | import org.onosproject.tetopology.management.api.TeTopology; |
| 26 | import org.onosproject.tetopology.management.api.link.TeLink; |
| 27 | import org.onosproject.tetopology.management.api.link.TeLinkTpGlobalKey; |
| 28 | import org.onosproject.tetopology.management.api.link.TeLinkTpKey; |
| 29 | import org.onosproject.tetopology.management.api.node.TeNode; |
| 30 | import org.onosproject.tetopology.management.api.node.TeNodeKey; |
| 31 | |
| 32 | import com.google.common.base.MoreObjects; |
| 33 | import com.google.common.base.Objects; |
| 34 | import com.google.common.collect.Lists; |
| 35 | |
| 36 | /** |
| 37 | * TE topology representation in store. |
| 38 | */ |
| 39 | public class InternalTeTopology { |
| 40 | private String teTopologyId; |
| 41 | private List<TeNodeKey> teNodeKeys; |
| 42 | private List<TeLinkTpGlobalKey> teLinkKeys; |
| 43 | private CommonTopologyData topologyData; |
| 44 | private long nextTeNodeId = NIL_LONG_VALUE; |
| 45 | private boolean childUpdate; |
| 46 | |
| 47 | /** |
| 48 | * Creates an instance of InternalTeTopology. |
| 49 | * |
| 50 | * @param teTopology the TE Topology object |
| 51 | */ |
| 52 | public InternalTeTopology(TeTopology teTopology) { |
| 53 | this.teTopologyId = teTopology.teTopologyIdStringValue(); |
| 54 | this.topologyData = new CommonTopologyData(teTopology); |
| 55 | // teNodeKeys |
| 56 | if (MapUtils.isNotEmpty(teTopology.teNodes())) { |
| 57 | this.teNodeKeys = Lists.newArrayList(); |
| 58 | for (Map.Entry<Long, TeNode> entry : teTopology.teNodes().entrySet()) { |
| 59 | this.teNodeKeys.add(new TeNodeKey(teTopology.teTopologyId(), entry.getKey())); |
| 60 | } |
| 61 | } |
| 62 | // teLink Keys |
| 63 | if (MapUtils.isNotEmpty(teTopology.teLinks())) { |
| 64 | this.teLinkKeys = Lists.newArrayList(); |
| 65 | for (Map.Entry<TeLinkTpKey, TeLink> entry : teTopology.teLinks().entrySet()) { |
| 66 | this.teLinkKeys.add(new TeLinkTpGlobalKey(teTopology.teTopologyId(), entry.getKey())); |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Creates a default instance of InternalNetwork. |
| 73 | * |
| 74 | * @param teTopologyId string value of id |
| 75 | */ |
| 76 | public InternalTeTopology(String teTopologyId) { |
| 77 | this.teTopologyId = teTopologyId; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Returns the TE Topology Id string value. |
| 82 | * |
| 83 | * @return the teTopologyId |
| 84 | */ |
| 85 | public String teTopologyId() { |
| 86 | return teTopologyId; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Returns the list of TE node keys in the topology. |
| 91 | * |
| 92 | * @return the teNodeKeys |
| 93 | */ |
| 94 | public List<TeNodeKey> teNodeKeys() { |
| 95 | return teNodeKeys; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Sets the list of TE node keys. |
| 100 | * |
| 101 | * @param teNodeKeys the teNodeKeys to set |
| 102 | */ |
| 103 | public void setTeNodeKeys(List<TeNodeKey> teNodeKeys) { |
| 104 | this.teNodeKeys = teNodeKeys; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Returns the list of TE link keys in the topology. |
| 109 | * |
| 110 | * @return the teLinkKeys |
| 111 | */ |
| 112 | public List<TeLinkTpGlobalKey> teLinkKeys() { |
| 113 | return teLinkKeys; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Sets the list of TE link keys. |
| 118 | * |
| 119 | * @param teLinkKeys the teLinkKeys to set |
| 120 | */ |
| 121 | public void setTeLinkKeys(List<TeLinkTpGlobalKey> teLinkKeys) { |
| 122 | this.teLinkKeys = teLinkKeys; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Returns the common TE topology data. |
| 127 | * |
| 128 | * @return the topology data |
| 129 | */ |
| 130 | public CommonTopologyData topologyData() { |
| 131 | return topologyData; |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Sets the common TE topology data. |
| 136 | * |
| 137 | * @param topologyData the topologyData to set |
| 138 | */ |
| 139 | public void setTopologydata(CommonTopologyData topologyData) { |
| 140 | this.topologyData = topologyData; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Returns the next available TE node Id. |
| 145 | * |
| 146 | * @return the next TE nodeId |
| 147 | */ |
| 148 | public long nextTeNodeId() { |
| 149 | return nextTeNodeId; |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Sets the next available TE node Id. |
| 154 | * |
| 155 | * @param nextTeNodeId the nextTeNodeId to set |
| 156 | */ |
| 157 | public void setNextTeNodeId(long nextTeNodeId) { |
| 158 | this.nextTeNodeId = nextTeNodeId; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Returns the flag if the data was updated by child change. |
| 163 | * |
| 164 | * @return value of childUpdate |
| 165 | */ |
| 166 | public boolean childUpdate() { |
| 167 | return childUpdate; |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Sets the flag if the data was updated by child change. |
| 172 | * |
| 173 | * @param childUpdate the childUpdate value to set |
| 174 | */ |
| 175 | public void setChildUpdate(boolean childUpdate) { |
| 176 | this.childUpdate = childUpdate; |
| 177 | } |
| 178 | |
| 179 | @Override |
| 180 | public int hashCode() { |
| 181 | return Objects.hashCode(teTopologyId, teNodeKeys, teLinkKeys, |
| 182 | topologyData); |
| 183 | } |
| 184 | |
| 185 | @Override |
| 186 | public boolean equals(Object object) { |
| 187 | if (this == object) { |
| 188 | return true; |
| 189 | } |
| 190 | if (object instanceof InternalTeTopology) { |
| 191 | InternalTeTopology that = (InternalTeTopology) object; |
| 192 | return Objects.equal(teTopologyId, that.teTopologyId) |
| 193 | && Objects.equal(teNodeKeys, that.teNodeKeys) |
| 194 | && Objects.equal(teLinkKeys, that.teLinkKeys) |
| 195 | && Objects.equal(topologyData, that.topologyData); |
| 196 | } |
| 197 | return false; |
| 198 | } |
| 199 | |
| 200 | @Override |
| 201 | public String toString() { |
| 202 | return MoreObjects.toStringHelper(this) |
| 203 | .add("teTopologyId", teTopologyId) |
| 204 | .add("teNodeKeys", teNodeKeys) |
| 205 | .add("teLinkKeys", teLinkKeys) |
| 206 | .add("topologyData", topologyData) |
| 207 | .add("nextTeNodeId", nextTeNodeId) |
| 208 | .add("childUpdate", childUpdate) |
| 209 | .toString(); |
| 210 | } |
| 211 | } |