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.link; |
| 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | import com.google.common.base.Objects; |
| 20 | import com.google.common.collect.ImmutableList; |
| 21 | import com.google.common.collect.Lists; |
| 22 | |
| 23 | import java.util.List; |
| 24 | |
| 25 | /** |
| 26 | * Represents the TE link underlay path and tunnel data. |
| 27 | */ |
| 28 | public class UnderlayPath { |
| 29 | private final UnderlayPrimaryPath primaryPath; |
| 30 | private final List<UnderlayBackupPath> backupPaths; |
| 31 | private final TunnelProtectionType tunnelProtectionType; |
| 32 | private final long srcTtpId; |
| 33 | private final long dstTtpId; |
| 34 | private final TeTunnelId teTunnelId; |
| 35 | |
| 36 | /** |
| 37 | * Creates a underlay path. |
| 38 | * |
| 39 | * @param primaryPath the underlay primary path |
| 40 | * @param backupPaths the underlay backup paths |
| 41 | * @param tunnelProtectionType the supporting tunnel protection type to set |
| 42 | * @param srcTtpId the source tunnel termination point id |
| 43 | * @param dstTtpId the destination tunnel termination point id |
| 44 | * @param teTunnelId the supporting TE tunnel id |
| 45 | */ |
| 46 | public UnderlayPath(UnderlayPrimaryPath primaryPath, |
| 47 | List<UnderlayBackupPath> backupPaths, |
| 48 | TunnelProtectionType tunnelProtectionType, |
| 49 | long srcTtpId, |
| 50 | long dstTtpId, |
| 51 | TeTunnelId teTunnelId) { |
| 52 | this.primaryPath = primaryPath; |
| 53 | this.backupPaths = backupPaths != null ? |
| 54 | Lists.newArrayList(backupPaths) : null; |
| 55 | this.tunnelProtectionType = tunnelProtectionType; |
| 56 | this.srcTtpId = srcTtpId; |
| 57 | this.dstTtpId = dstTtpId; |
| 58 | this.teTunnelId = teTunnelId; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Creates a underlay path based on a TE link. |
| 63 | * |
| 64 | * @param link the TE link |
| 65 | */ |
| 66 | public UnderlayPath(TeLink link) { |
| 67 | this.primaryPath = link.primaryPath(); |
| 68 | this.backupPaths = link.backupPaths() != null ? |
| 69 | Lists.newArrayList(link.backupPaths()) : null; |
| 70 | this.tunnelProtectionType = link.tunnelProtectionType(); |
| 71 | this.srcTtpId = link.sourceTtpId(); |
| 72 | this.dstTtpId = link.destinationTtpId(); |
| 73 | this.teTunnelId = link.teTunnelId(); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Returns the primary path. |
| 78 | * |
| 79 | * @return underlay primary path |
| 80 | */ |
| 81 | public UnderlayPrimaryPath primaryPath() { |
| 82 | return primaryPath; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Returns the backup paths. |
| 87 | * |
| 88 | * @return list of underlay backup paths |
| 89 | */ |
| 90 | public List<UnderlayBackupPath> backupPaths() { |
| 91 | if (backupPaths == null) { |
| 92 | return null; |
| 93 | } |
| 94 | return ImmutableList.copyOf(backupPaths); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Returns the supporting tunnel protection type. |
| 99 | * |
| 100 | * @return the supporting tunnel protection type |
| 101 | */ |
| 102 | public TunnelProtectionType tunnelProtectionType() { |
| 103 | return tunnelProtectionType; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Returns the supporting TE tunnel's source tunnel termination point |
| 108 | * identifier. |
| 109 | * |
| 110 | * @return the supporting source TTP id |
| 111 | */ |
| 112 | public long srcTtpId() { |
| 113 | return srcTtpId; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Returns the supporting TE tunnel's destination tunnel termination |
| 118 | * point identifier. |
| 119 | * |
| 120 | * @return the destination TTP id |
| 121 | */ |
| 122 | public long dstTtpId() { |
| 123 | return dstTtpId; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Returns the supporting TE tunnel identifier. |
| 128 | * |
| 129 | * @return the supporting tunnel id |
| 130 | */ |
| 131 | public TeTunnelId teTunnelId() { |
| 132 | return teTunnelId; |
| 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public int hashCode() { |
| 137 | return Objects.hashCode(primaryPath, backupPaths, tunnelProtectionType, |
| 138 | srcTtpId, dstTtpId, teTunnelId); |
| 139 | } |
| 140 | |
| 141 | @Override |
| 142 | public boolean equals(Object object) { |
| 143 | if (this == object) { |
| 144 | return true; |
| 145 | } |
| 146 | if (object instanceof UnderlayPath) { |
| 147 | UnderlayPath that = (UnderlayPath) object; |
| 148 | return Objects.equal(primaryPath, that.primaryPath) && |
| 149 | Objects.equal(backupPaths, that.backupPaths) && |
| 150 | Objects.equal(tunnelProtectionType, that.tunnelProtectionType) && |
| 151 | Objects.equal(srcTtpId, that.srcTtpId) && |
| 152 | Objects.equal(dstTtpId, that.dstTtpId) && |
| 153 | Objects.equal(teTunnelId, that.teTunnelId); |
| 154 | } |
| 155 | return false; |
| 156 | } |
| 157 | |
| 158 | @Override |
| 159 | public String toString() { |
| 160 | return MoreObjects.toStringHelper(this) |
| 161 | .add("primaryPath", primaryPath) |
| 162 | .add("backupPaths", backupPaths) |
| 163 | .add("tunnelProtectionType", tunnelProtectionType) |
| 164 | .add("srcTtpId", srcTtpId) |
| 165 | .add("dstTtpId", dstTtpId) |
| 166 | .add("teTunnelId", teTunnelId) |
| 167 | .toString(); |
| 168 | } |
| 169 | |
| 170 | } |