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; |
| 17 | |
Aihua Guo | 0bc1209 | 2017-02-10 09:53:55 -0500 | [diff] [blame] | 18 | import java.util.List; |
| 19 | import java.util.Map; |
| 20 | |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | import org.onosproject.tetopology.management.api.link.NetworkLink; |
| 23 | import org.onosproject.tetopology.management.api.node.NetworkNode; |
| 24 | |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 25 | import com.google.common.base.MoreObjects; |
| 26 | import com.google.common.base.Objects; |
| 27 | import com.google.common.collect.ImmutableList; |
| 28 | import com.google.common.collect.ImmutableMap; |
| 29 | import com.google.common.collect.Lists; |
| 30 | import com.google.common.collect.Maps; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Default Network implementation. |
| 34 | */ |
| 35 | public class DefaultNetwork implements Network { |
| 36 | private final KeyId networkId; |
| 37 | private final List<KeyId> supportingNetworkIds; |
| 38 | private final Map<KeyId, NetworkNode> nodes; |
| 39 | private final Map<KeyId, NetworkLink> links; |
| 40 | private final TeTopologyId teTopologyId; |
| 41 | private final boolean serverProvided; |
| 42 | private final DeviceId ownerId; |
Aihua Guo | 0bc1209 | 2017-02-10 09:53:55 -0500 | [diff] [blame] | 43 | private final OptimizationType optimization; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * Creates an instance of DefaultNetwork. |
| 47 | * |
Aihua Guo | 0bc1209 | 2017-02-10 09:53:55 -0500 | [diff] [blame] | 48 | * @param networkId network identifier |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 49 | * @param supportingNetworkIds supporting network identifier |
Aihua Guo | 0bc1209 | 2017-02-10 09:53:55 -0500 | [diff] [blame] | 50 | * @param nodes list of nodes within the network |
| 51 | * @param links list of links within the network |
| 52 | * @param teTopologyId TE topology identifier associated with the network |
| 53 | * @param serverProvided whether the network is received from server |
| 54 | * @param ownerId the the controller identifier owning this topology |
| 55 | * @param optimization TE topology optimization criteria |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 56 | */ |
| 57 | public DefaultNetwork(KeyId networkId, List<KeyId> supportingNetworkIds, |
| 58 | Map<KeyId, NetworkNode> nodes, Map<KeyId, NetworkLink> links, |
| 59 | TeTopologyId teTopologyId, boolean serverProvided, |
Aihua Guo | 0bc1209 | 2017-02-10 09:53:55 -0500 | [diff] [blame] | 60 | DeviceId ownerId, OptimizationType optimization) { |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 61 | this.networkId = networkId; |
| 62 | this.supportingNetworkIds = supportingNetworkIds != null ? |
| 63 | Lists.newArrayList(supportingNetworkIds) : null; |
| 64 | this.nodes = nodes != null ? Maps.newHashMap(nodes) : null; |
| 65 | this.links = links != null ? Maps.newHashMap(links) : null; |
| 66 | this.teTopologyId = teTopologyId; |
| 67 | this.serverProvided = serverProvided; |
| 68 | this.ownerId = ownerId; |
Aihua Guo | 0bc1209 | 2017-02-10 09:53:55 -0500 | [diff] [blame] | 69 | this.optimization = optimization; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | |
| 73 | @Override |
| 74 | public KeyId networkId() { |
| 75 | return networkId; |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public List<KeyId> supportingNetworkIds() { |
| 80 | if (supportingNetworkIds == null) { |
| 81 | return null; |
| 82 | } |
| 83 | return ImmutableList.copyOf(supportingNetworkIds); |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public Map<KeyId, NetworkNode> nodes() { |
| 88 | if (nodes == null) { |
| 89 | return null; |
| 90 | } |
| 91 | return ImmutableMap.copyOf(nodes); |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public NetworkNode node(KeyId nodeId) { |
| 96 | return nodes.get(nodeId); |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public Map<KeyId, NetworkLink> links() { |
| 101 | if (links == null) { |
| 102 | return null; |
| 103 | } |
| 104 | return ImmutableMap.copyOf(links); |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public NetworkLink link(KeyId linkId) { |
| 109 | return links.get(linkId); |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public boolean isServerProvided() { |
| 114 | return serverProvided; |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public TeTopologyId teTopologyId() { |
| 119 | return teTopologyId; |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public DeviceId ownerId() { |
| 124 | return ownerId; |
| 125 | } |
| 126 | |
| 127 | @Override |
Aihua Guo | 0bc1209 | 2017-02-10 09:53:55 -0500 | [diff] [blame] | 128 | public OptimizationType optimization() { |
| 129 | return optimization; |
| 130 | } |
| 131 | |
| 132 | @Override |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 133 | public int hashCode() { |
| 134 | return Objects.hashCode(networkId, supportingNetworkIds, |
Aihua Guo | 0bc1209 | 2017-02-10 09:53:55 -0500 | [diff] [blame] | 135 | nodes, links, serverProvided, teTopologyId, |
| 136 | ownerId, optimization); |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | @Override |
| 140 | public boolean equals(Object object) { |
| 141 | if (this == object) { |
| 142 | return true; |
| 143 | } |
| 144 | if (object instanceof DefaultNetwork) { |
| 145 | DefaultNetwork that = (DefaultNetwork) object; |
| 146 | return Objects.equal(networkId, that.networkId) && |
| 147 | Objects.equal(supportingNetworkIds, that.supportingNetworkIds) && |
| 148 | Objects.equal(nodes, that.nodes) && |
| 149 | Objects.equal(links, that.links) && |
| 150 | Objects.equal(serverProvided, that.serverProvided) && |
| 151 | Objects.equal(teTopologyId, that.teTopologyId) && |
Aihua Guo | 0bc1209 | 2017-02-10 09:53:55 -0500 | [diff] [blame] | 152 | Objects.equal(ownerId, that.ownerId) |
| 153 | && Objects.equal(optimization, that.optimization); |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 154 | } |
| 155 | return false; |
| 156 | } |
| 157 | |
| 158 | @Override |
| 159 | public String toString() { |
| 160 | return MoreObjects.toStringHelper(this) |
| 161 | .add("networkId", networkId) |
| 162 | .add("supportingNetworkIds", supportingNetworkIds) |
| 163 | .add("nodes", nodes) |
| 164 | .add("links", links) |
| 165 | .add("serverProvided", serverProvided) |
| 166 | .add("teTopologyId", teTopologyId) |
| 167 | .add("ownerId", ownerId) |
Aihua Guo | 0bc1209 | 2017-02-10 09:53:55 -0500 | [diff] [blame] | 168 | .add("optimization", optimization) |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 169 | .toString(); |
| 170 | } |
Aihua Guo | 0bc1209 | 2017-02-10 09:53:55 -0500 | [diff] [blame] | 171 | |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 172 | } |