Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0947d7e | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [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 | |
| 17 | package org.onosproject.segmentrouting.pwaas; |
| 18 | |
| 19 | |
| 20 | import com.google.common.base.MoreObjects; |
| 21 | import org.onlab.packet.MplsLabel; |
| 22 | import org.onlab.packet.VlanId; |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 23 | import org.onosproject.net.Link; |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 24 | |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 25 | import java.util.ArrayList; |
| 26 | import java.util.List; |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 27 | import java.util.Objects; |
| 28 | |
| 29 | import static com.google.common.base.Preconditions.checkArgument; |
| 30 | import static com.google.common.base.Preconditions.checkNotNull; |
| 31 | |
| 32 | /** |
| 33 | * Implementation of the default l2 tunnel. |
| 34 | */ |
| 35 | public class DefaultL2Tunnel { |
| 36 | |
| 37 | /** |
| 38 | * Mode of the pseudo wire. |
| 39 | */ |
| 40 | private L2Mode pwMode; |
| 41 | /** |
| 42 | * Service delimiting tag. |
| 43 | */ |
| 44 | private VlanId sdTag; |
| 45 | /** |
| 46 | * Tunnel id. |
| 47 | */ |
| 48 | private long tunnelId; |
| 49 | /** |
| 50 | * Pseudo wire label. |
| 51 | */ |
| 52 | private MplsLabel pwLabel; |
| 53 | /** |
| 54 | * Inter-CO label. |
| 55 | */ |
| 56 | private MplsLabel interCoLabel; |
| 57 | |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 58 | private List<Link> pathUsed; |
| 59 | |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 60 | /** |
Andreas Pantelopoulos | 0dec562 | 2018-02-13 15:38:53 -0800 | [diff] [blame^] | 61 | * Vlan which will be used for the encapsualted |
| 62 | * vlan traffic. |
| 63 | */ |
| 64 | private VlanId transportVlan; |
| 65 | |
| 66 | /** |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 67 | * Creates a inter-co l2 tunnel using the |
| 68 | * supplied parameters. |
| 69 | * |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 70 | * @param mode the tunnel mode |
| 71 | * @param sdtag the service delimiting tag |
| 72 | * @param tunnelId the tunnel id |
| 73 | * @param pwLabel the pseudo wire label |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 74 | * @param interCoLabel the inter central office label |
| 75 | */ |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 76 | public DefaultL2Tunnel(L2Mode mode, VlanId sdtag, long tunnelId, MplsLabel pwLabel, MplsLabel interCoLabel) { |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 77 | checkNotNull(mode); |
| 78 | checkArgument(tunnelId > 0); |
| 79 | checkNotNull(pwLabel); |
| 80 | checkNotNull(interCoLabel); |
| 81 | |
| 82 | this.pwMode = mode; |
| 83 | this.sdTag = sdtag; |
| 84 | this.tunnelId = tunnelId; |
| 85 | this.pwLabel = pwLabel; |
| 86 | this.interCoLabel = interCoLabel; |
| 87 | } |
| 88 | |
| 89 | /** |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 90 | * Creates a l2Tunnel from a given tunnel. |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 91 | * |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 92 | * @param l2Tunnel to replicate |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 93 | */ |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 94 | public DefaultL2Tunnel(DefaultL2Tunnel l2Tunnel) { |
| 95 | |
| 96 | this.pwMode = l2Tunnel.pwMode(); |
| 97 | this.sdTag = l2Tunnel.sdTag(); |
| 98 | this.tunnelId = l2Tunnel.tunnelId(); |
| 99 | this.pwLabel = l2Tunnel.pwLabel(); |
| 100 | this.interCoLabel = l2Tunnel.interCoLabel(); |
| 101 | this.pathUsed = l2Tunnel.pathUsed(); |
Andreas Pantelopoulos | 0dec562 | 2018-02-13 15:38:53 -0800 | [diff] [blame^] | 102 | this.transportVlan = l2Tunnel.transportVlan; |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /** |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 106 | * Creates a intra-co l2 tunnel using the |
| 107 | * supplied parameters. |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 108 | * |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 109 | * @param mode the tunnel mode |
| 110 | * @param sdtag the service delimiting tag |
| 111 | * @param tunnelId the tunnel id |
| 112 | * @param pwLabel the pseudo wire label |
| 113 | */ |
| 114 | public DefaultL2Tunnel(L2Mode mode, VlanId sdtag, long tunnelId, MplsLabel pwLabel) { |
| 115 | this(mode, sdtag, tunnelId, pwLabel, MplsLabel.mplsLabel(MplsLabel.MAX_MPLS)); |
| 116 | } |
| 117 | |
| 118 | |
| 119 | /** |
| 120 | * Creates an empty l2 tunnel. |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 121 | **/ |
| 122 | public DefaultL2Tunnel() { |
| 123 | this.pwMode = null; |
| 124 | this.sdTag = null; |
| 125 | this.tunnelId = 0; |
| 126 | this.pwLabel = null; |
| 127 | this.interCoLabel = null; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Returns the mode of the pseudo wire. |
| 132 | * |
| 133 | * @return the pseudo wire mode |
| 134 | */ |
| 135 | public L2Mode pwMode() { |
| 136 | return pwMode; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Returns the service delimitation |
| 141 | * tag. |
| 142 | * |
| 143 | * @return the service delimitation vlan id |
| 144 | */ |
| 145 | public VlanId sdTag() { |
| 146 | return sdTag; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Returns the tunnel id of the pseudo wire. |
| 151 | * |
| 152 | * @return the pseudo wire tunnel id |
| 153 | */ |
| 154 | public long tunnelId() { |
| 155 | return tunnelId; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Returns the pw label. |
| 160 | * |
| 161 | * @return the mpls pw label |
| 162 | */ |
| 163 | public MplsLabel pwLabel() { |
| 164 | return pwLabel; |
| 165 | } |
| 166 | |
| 167 | /** |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 168 | * Set the path for the pseudowire. |
| 169 | * |
| 170 | * @param path The path to set |
| 171 | */ |
| 172 | public void setPath(List<Link> path) { |
| 173 | pathUsed = new ArrayList<>(path); |
| 174 | } |
| 175 | |
| 176 | /** |
Andreas Pantelopoulos | 0dec562 | 2018-02-13 15:38:53 -0800 | [diff] [blame^] | 177 | * Set the transport vlan for the pseudowire. |
| 178 | * |
| 179 | * @param vlan the vlan to use. |
| 180 | */ |
| 181 | public void setTransportVlan(VlanId vlan) { |
| 182 | transportVlan = vlan; |
| 183 | } |
| 184 | |
| 185 | /** |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 186 | * Returns the used path of the pseudowire. |
| 187 | * |
| 188 | * @return pathUsed |
| 189 | */ |
| 190 | public List<Link> pathUsed() { |
| 191 | return pathUsed; |
| 192 | } |
| 193 | |
Andreas Pantelopoulos | 0dec562 | 2018-02-13 15:38:53 -0800 | [diff] [blame^] | 194 | public VlanId transportVlan() { |
| 195 | return transportVlan; |
| 196 | } |
| 197 | |
| 198 | |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 199 | /** |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 200 | * Returns the inter-co label. |
| 201 | * |
| 202 | * @return the mpls inter-co label |
| 203 | */ |
| 204 | public MplsLabel interCoLabel() { |
| 205 | return interCoLabel; |
| 206 | } |
| 207 | |
| 208 | @Override |
| 209 | public int hashCode() { |
Ray Milkey | eae2b99 | 2017-12-15 15:14:06 -0800 | [diff] [blame] | 210 | return Objects.hash(this.tunnelId, this.pwMode, this.sdTag, this.pwLabel, this.interCoLabel); |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | @Override |
| 214 | public boolean equals(Object o) { |
| 215 | if (this == o) { |
| 216 | return true; |
| 217 | } |
| 218 | |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 219 | if (o instanceof DefaultL2Tunnel) { |
| 220 | DefaultL2Tunnel that = (DefaultL2Tunnel) o; |
| 221 | return this.tunnelId == that.tunnelId && |
| 222 | this.pwMode.equals(that.pwMode) && |
| 223 | this.sdTag.equals(that.sdTag) && |
| 224 | this.pwLabel.equals(that.pwLabel) && |
| 225 | this.interCoLabel.equals(that.interCoLabel); |
| 226 | } |
| 227 | |
| 228 | return false; |
| 229 | } |
| 230 | |
| 231 | @Override |
| 232 | public String toString() { |
| 233 | return MoreObjects.toStringHelper(this) |
| 234 | .add("pwMode", pwMode()) |
| 235 | .add("sdTag", sdTag()) |
| 236 | .add("tunnelId", tunnelId()) |
| 237 | .add("pwLabel", pwLabel()) |
| 238 | .add("interCoLabel", interCoLabel()) |
Andreas Pantelopoulos | 0dec562 | 2018-02-13 15:38:53 -0800 | [diff] [blame^] | 239 | .add("transportVlan", transportVlan()) |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 240 | .toString(); |
| 241 | } |
| 242 | |
| 243 | } |