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 java.util.List; |
| 19 | import java.util.Map; |
| 20 | |
| 21 | import org.apache.commons.collections.MapUtils; |
| 22 | import org.onosproject.tetopology.management.api.KeyId; |
| 23 | import org.onosproject.tetopology.management.api.Network; |
| 24 | import org.onosproject.tetopology.management.api.TeTopologyKey; |
| 25 | import org.onosproject.tetopology.management.api.link.NetworkLink; |
| 26 | import org.onosproject.tetopology.management.api.link.NetworkLinkKey; |
| 27 | import org.onosproject.tetopology.management.api.node.NetworkNode; |
| 28 | import org.onosproject.tetopology.management.api.node.NetworkNodeKey; |
| 29 | |
| 30 | import com.google.common.base.MoreObjects; |
| 31 | import com.google.common.base.Objects; |
| 32 | import com.google.common.collect.ImmutableList; |
| 33 | import com.google.common.collect.Lists; |
| 34 | |
| 35 | /** |
| 36 | * Network representation in store. |
| 37 | */ |
| 38 | public class InternalNetwork { |
| 39 | private TeTopologyKey teTopologyKey; |
| 40 | private List<KeyId> supportingNetworkIds; |
| 41 | private boolean serverProvided; |
| 42 | private List<NetworkNodeKey> nodeIds; |
| 43 | private List<NetworkLinkKey> linkIds; |
| 44 | private boolean childUpdate = false; |
| 45 | |
| 46 | /** |
| 47 | * Creates an instance of InternalNetwork. |
| 48 | * |
| 49 | * @param network the Network object |
| 50 | */ |
| 51 | public InternalNetwork(Network network) { |
| 52 | this.supportingNetworkIds = network |
| 53 | .supportingNetworkIds() == null ? null |
| 54 | : Lists.newArrayList(network |
| 55 | .supportingNetworkIds()); |
| 56 | this.serverProvided = network.isServerProvided(); |
| 57 | // NetworkNodeKey |
| 58 | if (MapUtils.isNotEmpty(network.nodes())) { |
| 59 | this.nodeIds = Lists.newArrayList(); |
| 60 | for (Map.Entry<KeyId, NetworkNode> entry : network.nodes().entrySet()) { |
| 61 | this.nodeIds.add(new NetworkNodeKey(network.networkId(), entry.getKey())); |
| 62 | } |
| 63 | } |
| 64 | // NetworkLinkKey |
| 65 | if (MapUtils.isNotEmpty(network.links())) { |
| 66 | this.linkIds = Lists.newArrayList(); |
| 67 | for (Map.Entry<KeyId, NetworkLink> entry : network.links().entrySet()) { |
| 68 | this.linkIds.add(new NetworkLinkKey(network.networkId(), entry.getKey())); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Creates a default instance of InternalNetwork. |
| 75 | */ |
| 76 | public InternalNetwork() { |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Returns the supporting network Ids. |
| 81 | * |
| 82 | * @return the supportingNetworkIds |
| 83 | */ |
| 84 | public List<KeyId> supportingNetworkIds() { |
| 85 | if (supportingNetworkIds == null) { |
| 86 | return null; |
| 87 | } |
| 88 | return ImmutableList.copyOf(supportingNetworkIds); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Returns if the network topology is provided by a server or is |
| 93 | * configured by a client. |
| 94 | * |
| 95 | * @return true if the network is provided by a server; false otherwise |
| 96 | */ |
| 97 | public boolean serverProvided() { |
| 98 | return serverProvided; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * @param serverProvided the serverProvided to set |
| 103 | */ |
| 104 | public void setServerProvided(boolean serverProvided) { |
| 105 | this.serverProvided = serverProvided; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Returns the list of node Ids in the network. |
| 110 | * |
| 111 | * @return the nodeIds |
| 112 | */ |
| 113 | public List<NetworkNodeKey> nodeIds() { |
| 114 | return nodeIds; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Returns the TE topology key for the network. |
| 119 | * |
| 120 | * @return the teTopologyKey |
| 121 | */ |
| 122 | public TeTopologyKey teTopologyKey() { |
| 123 | return teTopologyKey; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Sets the TE topology key for the network. |
| 128 | * |
| 129 | * @param teTopologyKey the teTopologyKey to set |
| 130 | */ |
| 131 | public void setTeTopologyKey(TeTopologyKey teTopologyKey) { |
| 132 | this.teTopologyKey = teTopologyKey; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Set the list of node Ids in the network. |
| 137 | * |
| 138 | * @param nodeIds the nodeIds to set |
| 139 | */ |
| 140 | public void setNodeIds(List<NetworkNodeKey> nodeIds) { |
| 141 | this.nodeIds = nodeIds; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Returns the list of link Ids in the network. |
| 146 | * |
| 147 | * @return the linkIds |
| 148 | */ |
| 149 | public List<NetworkLinkKey> linkIds() { |
| 150 | return linkIds; |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * Set the list of link Ids in the network. |
| 155 | * |
| 156 | * @param linkIds the linkIds to set |
| 157 | */ |
| 158 | public void setLinkIds(List<NetworkLinkKey> linkIds) { |
| 159 | this.linkIds = linkIds; |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Returns the flag if the data was updated by child change. |
| 164 | * |
| 165 | * @return value of childUpdate |
| 166 | */ |
| 167 | public boolean childUpdate() { |
| 168 | return childUpdate; |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Sets the flag if the data was updated by child change. |
| 173 | * |
| 174 | * @param childUpdate the childUpdate value to set |
| 175 | */ |
| 176 | public void setChildUpdate(boolean childUpdate) { |
| 177 | this.childUpdate = childUpdate; |
| 178 | } |
| 179 | |
| 180 | @Override |
| 181 | public int hashCode() { |
| 182 | return Objects.hashCode(teTopologyKey, nodeIds, linkIds, |
| 183 | supportingNetworkIds, serverProvided); |
| 184 | } |
| 185 | |
| 186 | @Override |
| 187 | public boolean equals(Object object) { |
| 188 | if (this == object) { |
| 189 | return true; |
| 190 | } |
| 191 | if (object instanceof InternalNetwork) { |
| 192 | InternalNetwork that = (InternalNetwork) object; |
| 193 | return Objects.equal(this.teTopologyKey, that.teTopologyKey) && |
| 194 | Objects.equal(this.nodeIds, that.nodeIds) && |
| 195 | Objects.equal(this.linkIds, that.linkIds) && |
| 196 | Objects.equal(this.supportingNetworkIds, that.supportingNetworkIds) && |
| 197 | Objects.equal(this.serverProvided, that.serverProvided); |
| 198 | } |
| 199 | return false; |
| 200 | } |
| 201 | |
| 202 | @Override |
| 203 | public String toString() { |
| 204 | return MoreObjects.toStringHelper(this) |
| 205 | .add("teTopologyKey", teTopologyKey) |
| 206 | .add("nodeIds", nodeIds) |
| 207 | .add("linkIds", linkIds) |
| 208 | .add("supportingNetworkIds", supportingNetworkIds) |
| 209 | .add("serverProvided", serverProvided) |
| 210 | .add("childUpdate", childUpdate) |
| 211 | .toString(); |
| 212 | } |
| 213 | |
| 214 | } |