blob: fd726c983d538edef04ddf1f690913afea937c70 [file] [log] [blame]
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016 Open Networking Foundation
Henry Yu4b4a7eb2016-11-09 20:07:53 -05003 *
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 */
16package org.onosproject.tetopology.management.api;
17
Aihua Guo0bc12092017-02-10 09:53:55 -050018import java.util.List;
19import java.util.Map;
20
21import org.onosproject.net.DeviceId;
22import org.onosproject.tetopology.management.api.link.NetworkLink;
23import org.onosproject.tetopology.management.api.node.NetworkNode;
24
Henry Yu4b4a7eb2016-11-09 20:07:53 -050025import com.google.common.base.MoreObjects;
26import com.google.common.base.Objects;
27import com.google.common.collect.ImmutableList;
28import com.google.common.collect.ImmutableMap;
29import com.google.common.collect.Lists;
30import com.google.common.collect.Maps;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050031
32/**
33 * Default Network implementation.
34 */
35public 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 Guo0bc12092017-02-10 09:53:55 -050043 private final OptimizationType optimization;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050044
45 /**
46 * Creates an instance of DefaultNetwork.
47 *
Aihua Guo0bc12092017-02-10 09:53:55 -050048 * @param networkId network identifier
Henry Yu4b4a7eb2016-11-09 20:07:53 -050049 * @param supportingNetworkIds supporting network identifier
Aihua Guo0bc12092017-02-10 09:53:55 -050050 * @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 Yu4b4a7eb2016-11-09 20:07:53 -050056 */
57 public DefaultNetwork(KeyId networkId, List<KeyId> supportingNetworkIds,
58 Map<KeyId, NetworkNode> nodes, Map<KeyId, NetworkLink> links,
59 TeTopologyId teTopologyId, boolean serverProvided,
Aihua Guo0bc12092017-02-10 09:53:55 -050060 DeviceId ownerId, OptimizationType optimization) {
Henry Yu4b4a7eb2016-11-09 20:07:53 -050061 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 Guo0bc12092017-02-10 09:53:55 -050069 this.optimization = optimization;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050070 }
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 Guo0bc12092017-02-10 09:53:55 -0500128 public OptimizationType optimization() {
129 return optimization;
130 }
131
132 @Override
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500133 public int hashCode() {
134 return Objects.hashCode(networkId, supportingNetworkIds,
Aihua Guo0bc12092017-02-10 09:53:55 -0500135 nodes, links, serverProvided, teTopologyId,
136 ownerId, optimization);
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500137 }
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 Guo0bc12092017-02-10 09:53:55 -0500152 Objects.equal(ownerId, that.ownerId)
153 && Objects.equal(optimization, that.optimization);
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500154 }
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 Guo0bc12092017-02-10 09:53:55 -0500168 .add("optimization", optimization)
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500169 .toString();
170 }
Aihua Guo0bc12092017-02-10 09:53:55 -0500171
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500172}