blob: efe82f1b7b1894b34a174b6e947f083eedafd216 [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.node;
17
Yixiao Chen265b3bb2017-01-13 10:17:03 -050018import java.util.Arrays;
19import java.util.BitSet;
20import java.util.List;
21
22import org.onosproject.tetopology.management.api.EncodingType;
23import org.onosproject.tetopology.management.api.SwitchingType;
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.Lists;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050029
30/**
31 * Default implementation of a tunnel termination point.
32 */
33public class DefaultTunnelTerminationPoint implements TunnelTerminationPoint {
34 private final long ttpId;
35 private final SwitchingType switchingLayer;
36 private final EncodingType encodingLayer;
37 private final BitSet flags;
38 private final List<Long> interLayerLockList;
39 private final List<LocalLinkConnectivity> localLinkConnectivityList;
40 private final float[] availAdaptBandwidth;
Yixiao Chen265b3bb2017-01-13 10:17:03 -050041 private final TtpKey supportTtpKey;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050042
43 /**
44 * Create a tunnel termination point.
45 *
46 * @param ttpId tunnel termination point id
47 * @param switchingLayer switching network layer to which this
48 * TTP belongs
49 * @param encodingLayer encoding layer to which this TTP belongs
50 * @param flags the TTP flags
51 * @param interLayerLockList the supported inter-layer locks
52 * @param localLinkConnectivityList the local link connectivity list
53 * @param availAdaptBandwidth the remaining adaptation bandwidth
54 * at each priority level
Yixiao Chen265b3bb2017-01-13 10:17:03 -050055 * @param supportTtpKey supporting TTP key from underlay topology
Henry Yu4b4a7eb2016-11-09 20:07:53 -050056 */
57 public DefaultTunnelTerminationPoint(long ttpId,
58 SwitchingType switchingLayer,
59 EncodingType encodingLayer,
60 BitSet flags,
61 List<Long> interLayerLockList,
62 List<LocalLinkConnectivity> localLinkConnectivityList,
Yixiao Chen265b3bb2017-01-13 10:17:03 -050063 float[] availAdaptBandwidth,
64 TtpKey supportTtpKey) {
Henry Yu4b4a7eb2016-11-09 20:07:53 -050065 this.ttpId = ttpId;
66 this.switchingLayer = switchingLayer;
67 this.encodingLayer = encodingLayer;
68 this.flags = flags;
69 this.interLayerLockList = interLayerLockList != null ?
70 Lists.newArrayList(interLayerLockList) : null;
71 this.localLinkConnectivityList = localLinkConnectivityList != null ?
72 Lists.newArrayList(localLinkConnectivityList) : null;
73 this.availAdaptBandwidth = availAdaptBandwidth != null ?
74 Arrays.copyOf(availAdaptBandwidth,
75 availAdaptBandwidth.length) : null;
Yixiao Chen265b3bb2017-01-13 10:17:03 -050076 this.supportTtpKey = supportTtpKey;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050077 }
78
79 @Override
80 public long ttpId() {
81 return ttpId;
82 }
83
84 @Override
85 public SwitchingType switchingLayer() {
86 return switchingLayer;
87 }
88
89 @Override
90 public EncodingType encodingLayer() {
91 return encodingLayer;
92 }
93
94 @Override
95 public BitSet flags() {
96 return flags;
97 }
98
99 @Override
100 public List<Long> interLayerLockList() {
101 if (interLayerLockList == null) {
102 return null;
103 }
104 return ImmutableList.copyOf(interLayerLockList);
105 }
106
107 @Override
108 public List<LocalLinkConnectivity> localLinkConnectivityList() {
109 if (localLinkConnectivityList == null) {
110 return null;
111 }
112 return ImmutableList.copyOf(localLinkConnectivityList);
113 }
114
115 @Override
116 public float[] availAdaptBandwidth() {
117 if (availAdaptBandwidth == null) {
118 return null;
119 }
120 return Arrays.copyOf(availAdaptBandwidth, availAdaptBandwidth.length);
121 }
122
123 @Override
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500124 public TtpKey supportingTtpId() {
125 return supportTtpKey;
126 }
127
128 @Override
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500129 public int hashCode() {
130 return Objects.hashCode(ttpId, switchingLayer, encodingLayer, flags,
131 interLayerLockList, localLinkConnectivityList,
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500132 Arrays.hashCode(availAdaptBandwidth), supportTtpKey);
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500133 }
134
135 @Override
136 public boolean equals(Object object) {
137 if (this == object) {
138 return true;
139 }
140 if (object instanceof DefaultTunnelTerminationPoint) {
141 DefaultTunnelTerminationPoint that = (DefaultTunnelTerminationPoint) object;
142 return Objects.equal(ttpId, that.ttpId) &&
143 Objects.equal(switchingLayer, that.switchingLayer) &&
144 Objects.equal(encodingLayer, that.encodingLayer) &&
145 Objects.equal(flags, that.flags) &&
146 Objects.equal(interLayerLockList, that.interLayerLockList) &&
147 Objects.equal(localLinkConnectivityList, that.localLinkConnectivityList) &&
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500148 Arrays.equals(availAdaptBandwidth, that.availAdaptBandwidth) &&
149 Objects.equal(supportTtpKey, that.supportTtpKey);
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500150 }
151 return false;
152 }
153
154 @Override
155 public String toString() {
156 return MoreObjects.toStringHelper(this)
157 .add("ttpId", ttpId)
158 .add("switchingLayer", switchingLayer)
159 .add("encodingLayer", encodingLayer)
160 .add("flags", flags)
161 .add("interLayerLockList", interLayerLockList)
162 .add("localLinkConnectivityList", localLinkConnectivityList)
163 .add("availAdaptBandwidth", availAdaptBandwidth)
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500164 .add("supportTtpKey", supportTtpKey)
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500165 .toString();
166 }
Yixiao Chen265b3bb2017-01-13 10:17:03 -0500167
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500168}