blob: fd419eefbbb5a8b6748d736cacb0fbd4aa255cd0 [file] [log] [blame]
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001/*
2 * Copyright 2016 Open Networking Laboratory
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 */
16package org.onosproject.tetopology.management.api.node;
17
18import com.google.common.base.MoreObjects;
19import com.google.common.base.Objects;
20import com.google.common.collect.ImmutableList;
21import com.google.common.collect.Lists;
22import org.onosproject.tetopology.management.api.EncodingType;
23import org.onosproject.tetopology.management.api.SwitchingType;
24
25import java.util.Arrays;
26import java.util.BitSet;
27import java.util.List;
28
29/**
30 * Default implementation of a tunnel termination point.
31 */
32public class DefaultTunnelTerminationPoint implements TunnelTerminationPoint {
33 private final long ttpId;
34 private final SwitchingType switchingLayer;
35 private final EncodingType encodingLayer;
36 private final BitSet flags;
37 private final List<Long> interLayerLockList;
38 private final List<LocalLinkConnectivity> localLinkConnectivityList;
39 private final float[] availAdaptBandwidth;
40
41 /**
42 * Create a tunnel termination point.
43 *
44 * @param ttpId tunnel termination point id
45 * @param switchingLayer switching network layer to which this
46 * TTP belongs
47 * @param encodingLayer encoding layer to which this TTP belongs
48 * @param flags the TTP flags
49 * @param interLayerLockList the supported inter-layer locks
50 * @param localLinkConnectivityList the local link connectivity list
51 * @param availAdaptBandwidth the remaining adaptation bandwidth
52 * at each priority level
53 */
54 public DefaultTunnelTerminationPoint(long ttpId,
55 SwitchingType switchingLayer,
56 EncodingType encodingLayer,
57 BitSet flags,
58 List<Long> interLayerLockList,
59 List<LocalLinkConnectivity> localLinkConnectivityList,
60 float[] availAdaptBandwidth) {
61 this.ttpId = ttpId;
62 this.switchingLayer = switchingLayer;
63 this.encodingLayer = encodingLayer;
64 this.flags = flags;
65 this.interLayerLockList = interLayerLockList != null ?
66 Lists.newArrayList(interLayerLockList) : null;
67 this.localLinkConnectivityList = localLinkConnectivityList != null ?
68 Lists.newArrayList(localLinkConnectivityList) : null;
69 this.availAdaptBandwidth = availAdaptBandwidth != null ?
70 Arrays.copyOf(availAdaptBandwidth,
71 availAdaptBandwidth.length) : null;
72 }
73
74 @Override
75 public long ttpId() {
76 return ttpId;
77 }
78
79 @Override
80 public SwitchingType switchingLayer() {
81 return switchingLayer;
82 }
83
84 @Override
85 public EncodingType encodingLayer() {
86 return encodingLayer;
87 }
88
89 @Override
90 public BitSet flags() {
91 return flags;
92 }
93
94 @Override
95 public List<Long> interLayerLockList() {
96 if (interLayerLockList == null) {
97 return null;
98 }
99 return ImmutableList.copyOf(interLayerLockList);
100 }
101
102 @Override
103 public List<LocalLinkConnectivity> localLinkConnectivityList() {
104 if (localLinkConnectivityList == null) {
105 return null;
106 }
107 return ImmutableList.copyOf(localLinkConnectivityList);
108 }
109
110 @Override
111 public float[] availAdaptBandwidth() {
112 if (availAdaptBandwidth == null) {
113 return null;
114 }
115 return Arrays.copyOf(availAdaptBandwidth, availAdaptBandwidth.length);
116 }
117
118 @Override
119 public int hashCode() {
120 return Objects.hashCode(ttpId, switchingLayer, encodingLayer, flags,
121 interLayerLockList, localLinkConnectivityList,
kdarapu95eb7d32017-01-04 14:41:11 +0530122 Arrays.hashCode(availAdaptBandwidth));
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500123 }
124
125 @Override
126 public boolean equals(Object object) {
127 if (this == object) {
128 return true;
129 }
130 if (object instanceof DefaultTunnelTerminationPoint) {
131 DefaultTunnelTerminationPoint that = (DefaultTunnelTerminationPoint) object;
132 return Objects.equal(ttpId, that.ttpId) &&
133 Objects.equal(switchingLayer, that.switchingLayer) &&
134 Objects.equal(encodingLayer, that.encodingLayer) &&
135 Objects.equal(flags, that.flags) &&
136 Objects.equal(interLayerLockList, that.interLayerLockList) &&
137 Objects.equal(localLinkConnectivityList, that.localLinkConnectivityList) &&
kdarapu95eb7d32017-01-04 14:41:11 +0530138 Arrays.equals(availAdaptBandwidth, that.availAdaptBandwidth);
Henry Yu4b4a7eb2016-11-09 20:07:53 -0500139 }
140 return false;
141 }
142
143 @Override
144 public String toString() {
145 return MoreObjects.toStringHelper(this)
146 .add("ttpId", ttpId)
147 .add("switchingLayer", switchingLayer)
148 .add("encodingLayer", encodingLayer)
149 .add("flags", flags)
150 .add("interLayerLockList", interLayerLockList)
151 .add("localLinkConnectivityList", localLinkConnectivityList)
152 .add("availAdaptBandwidth", availAdaptBandwidth)
153 .toString();
154 }
155}