blob: 7d822959b47b99358d8d9047450cb768946361f5 [file] [log] [blame]
Yixiao Chen68bfab22016-11-11 11:04:10 -05001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Yixiao Chen68bfab22016-11-11 11:04:10 -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.impl;
17
18import java.util.List;
19
20import org.onosproject.tetopology.management.api.link.NetworkLink;
21import org.onosproject.tetopology.management.api.link.NetworkLinkKey;
22import org.onosproject.tetopology.management.api.link.TeLinkTpGlobalKey;
23import org.onosproject.tetopology.management.api.node.NodeTpKey;
24
25import com.google.common.base.MoreObjects;
26import com.google.common.base.Objects;
27import com.google.common.collect.ImmutableList;
28import com.google.common.collect.Lists;
29
30/**
31 * Network Link representation in store.
32 */
33public class InternalNetworkLink {
34 private NodeTpKey source;
35 private NodeTpKey destination;
36 private List<NetworkLinkKey> supportingLinkIds;
37 private TeLinkTpGlobalKey teLinkKey;
38 private boolean parentUpdate;
39
40 /**
41 * Creates an instance of InternalNetworkLink.
42 *
43 * @param link the network link
44 * @param parentUpdate the flag if the data is updated by parent
45 */
46 public InternalNetworkLink(NetworkLink link, boolean parentUpdate) {
47 source = link.source();
48 destination = link.destination();
49 supportingLinkIds = link
50 .supportingLinkIds() == null ? null
51 : Lists.newArrayList(link
52 .supportingLinkIds());
53 this.parentUpdate = parentUpdate;
54 }
55
56 /**
57 * Returns the link source termination point.
58 *
59 * @return source link termination point id
60 */
61 public NodeTpKey source() {
62 return source;
63 }
64
65 /**
66 * Returns the link destination termination point.
67 *
68 * @return destination link termination point id
69 */
70 public NodeTpKey destination() {
71 return destination;
72 }
73
74 /**
75 * Returns the supporting link ids.
76 *
77 * @return list of the ids of the supporting links
78 */
79 public List<NetworkLinkKey> supportingLinkIds() {
80 return supportingLinkIds == null ? null
81 : ImmutableList
82 .copyOf(supportingLinkIds);
83 }
84
85 /**
86 * Returns the TE link key.
87 *
88 * @return the teLinkKey
89 */
90 public TeLinkTpGlobalKey teLinkKey() {
91 return teLinkKey;
92 }
93
94 /**
95 * Sets the TE link key.
96 *
97 * @param teLinkKey the teLinkKey to set
98 */
99 public void setTeLinkKey(TeLinkTpGlobalKey teLinkKey) {
100 this.teLinkKey = teLinkKey;
101 }
102
103 /**
104 * Returns the flag if the data was updated by parent change.
105 *
106 * @return value of parentUpdate
107 */
108 public boolean parentUpdate() {
109 return parentUpdate;
110 }
111
112 @Override
113 public int hashCode() {
114 return Objects.hashCode(source, destination, supportingLinkIds, teLinkKey);
115 }
116
117 @Override
118 public boolean equals(Object object) {
119 if (this == object) {
120 return true;
121 }
122 if (object instanceof InternalNetworkLink) {
123 InternalNetworkLink that = (InternalNetworkLink) object;
124 return Objects.equal(source, that.source)
125 && Objects.equal(destination, that.destination)
126 && Objects.equal(supportingLinkIds, that.supportingLinkIds)
127 && Objects.equal(teLinkKey, that.teLinkKey);
128 }
129 return false;
130 }
131
132 @Override
133 public String toString() {
134 return MoreObjects.toStringHelper(this)
135 .add("source", source)
136 .add("destination", destination)
137 .add("supportingLinkIds", supportingLinkIds)
138 .add("teLinkKey", teLinkKey)
139 .toString();
140 }
141}