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.node; |
| 17 | |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 18 | import java.util.Arrays; |
| 19 | import java.util.BitSet; |
| 20 | import java.util.List; |
| 21 | |
| 22 | import org.onosproject.tetopology.management.api.EncodingType; |
| 23 | import org.onosproject.tetopology.management.api.SwitchingType; |
| 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.Lists; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * Default implementation of a tunnel termination point. |
| 32 | */ |
| 33 | public 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 Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 41 | private final TtpKey supportTtpKey; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 42 | |
| 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 Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 55 | * @param supportTtpKey supporting TTP key from underlay topology |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 56 | */ |
| 57 | public DefaultTunnelTerminationPoint(long ttpId, |
| 58 | SwitchingType switchingLayer, |
| 59 | EncodingType encodingLayer, |
| 60 | BitSet flags, |
| 61 | List<Long> interLayerLockList, |
| 62 | List<LocalLinkConnectivity> localLinkConnectivityList, |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 63 | float[] availAdaptBandwidth, |
| 64 | TtpKey supportTtpKey) { |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 65 | 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 Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 76 | this.supportTtpKey = supportTtpKey; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 77 | } |
| 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 Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 124 | public TtpKey supportingTtpId() { |
| 125 | return supportTtpKey; |
| 126 | } |
| 127 | |
| 128 | @Override |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 129 | public int hashCode() { |
| 130 | return Objects.hashCode(ttpId, switchingLayer, encodingLayer, flags, |
| 131 | interLayerLockList, localLinkConnectivityList, |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 132 | Arrays.hashCode(availAdaptBandwidth), supportTtpKey); |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 133 | } |
| 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 Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 148 | Arrays.equals(availAdaptBandwidth, that.availAdaptBandwidth) && |
| 149 | Objects.equal(supportTtpKey, that.supportTtpKey); |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 150 | } |
| 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 Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 164 | .add("supportTtpKey", supportTtpKey) |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 165 | .toString(); |
| 166 | } |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 167 | |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 168 | } |