blob: 417a7955d791e55864de8f185ef2b5040d62a431 [file] [log] [blame]
Pier Ventre6b19e482016-11-07 16:21:04 -08001/*
Brian O'Connor0947d7e2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Pier Ventre6b19e482016-11-07 16:21:04 -08003 *
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
17package org.onosproject.segmentrouting.pwaas;
18
19
20import com.google.common.base.MoreObjects;
21import org.onlab.packet.MplsLabel;
22import org.onlab.packet.VlanId;
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070023import org.onosproject.net.Link;
Pier Ventre6b19e482016-11-07 16:21:04 -080024
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070025import java.util.ArrayList;
26import java.util.List;
Pier Ventre6b19e482016-11-07 16:21:04 -080027import java.util.Objects;
28
29import static com.google.common.base.Preconditions.checkArgument;
30import static com.google.common.base.Preconditions.checkNotNull;
31
32/**
33 * Implementation of the default l2 tunnel.
34 */
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -080035public class DefaultL2Tunnel implements L2Tunnel {
Pier Ventre6b19e482016-11-07 16:21:04 -080036
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 Pantelopoulos5e7be3d2017-10-23 12:18:25 -070058 private List<Link> pathUsed;
59
Pier Ventre6b19e482016-11-07 16:21:04 -080060 /**
Andreas Pantelopoulos0dec5622018-02-13 15:38:53 -080061 * Vlan which will be used for the encapsualted
62 * vlan traffic.
63 */
64 private VlanId transportVlan;
65
66 /**
Pier Ventre6b19e482016-11-07 16:21:04 -080067 * Creates a inter-co l2 tunnel using the
68 * supplied parameters.
69 *
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070070 * @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 Ventre6b19e482016-11-07 16:21:04 -080074 * @param interCoLabel the inter central office label
75 */
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070076 public DefaultL2Tunnel(L2Mode mode, VlanId sdtag, long tunnelId, MplsLabel pwLabel, MplsLabel interCoLabel) {
Pier Ventre6b19e482016-11-07 16:21:04 -080077 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 Pantelopoulos5e7be3d2017-10-23 12:18:25 -070090 * Creates a l2Tunnel from a given tunnel.
Pier Ventre6b19e482016-11-07 16:21:04 -080091 *
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070092 * @param l2Tunnel to replicate
Pier Ventre6b19e482016-11-07 16:21:04 -080093 */
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070094 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 Pantelopoulos0dec5622018-02-13 15:38:53 -0800102 this.transportVlan = l2Tunnel.transportVlan;
Pier Ventre6b19e482016-11-07 16:21:04 -0800103 }
104
105 /**
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700106 * Creates a intra-co l2 tunnel using the
107 * supplied parameters.
Pier Ventre6b19e482016-11-07 16:21:04 -0800108 *
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700109 * @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 Ventre6b19e482016-11-07 16:21:04 -0800121 **/
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 */
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800135 @Override
Pier Ventre6b19e482016-11-07 16:21:04 -0800136 public L2Mode pwMode() {
137 return pwMode;
138 }
139
140 /**
141 * Returns the service delimitation
142 * tag.
143 *
144 * @return the service delimitation vlan id
145 */
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800146 @Override
Pier Ventre6b19e482016-11-07 16:21:04 -0800147 public VlanId sdTag() {
148 return sdTag;
149 }
150
151 /**
152 * Returns the tunnel id of the pseudo wire.
153 *
154 * @return the pseudo wire tunnel id
155 */
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800156 @Override
Pier Ventre6b19e482016-11-07 16:21:04 -0800157 public long tunnelId() {
158 return tunnelId;
159 }
160
161 /**
162 * Returns the pw label.
163 *
164 * @return the mpls pw label
165 */
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800166 @Override
Pier Ventre6b19e482016-11-07 16:21:04 -0800167 public MplsLabel pwLabel() {
168 return pwLabel;
169 }
170
171 /**
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700172 * Set the path for the pseudowire.
173 *
174 * @param path The path to set
175 */
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800176 @Override
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700177 public void setPath(List<Link> path) {
178 pathUsed = new ArrayList<>(path);
179 }
180
181 /**
Andreas Pantelopoulos0dec5622018-02-13 15:38:53 -0800182 * Set the transport vlan for the pseudowire.
183 *
184 * @param vlan the vlan to use.
185 */
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800186 @Override
Andreas Pantelopoulos0dec5622018-02-13 15:38:53 -0800187 public void setTransportVlan(VlanId vlan) {
188 transportVlan = vlan;
189 }
190
191 /**
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700192 * Returns the used path of the pseudowire.
193 *
194 * @return pathUsed
195 */
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800196 @Override
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700197 public List<Link> pathUsed() {
198 return pathUsed;
199 }
200
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800201 @Override
Andreas Pantelopoulos0dec5622018-02-13 15:38:53 -0800202 public VlanId transportVlan() {
203 return transportVlan;
204 }
205
206
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700207 /**
Pier Ventre6b19e482016-11-07 16:21:04 -0800208 * Returns the inter-co label.
209 *
210 * @return the mpls inter-co label
211 */
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800212 @Override
Pier Ventre6b19e482016-11-07 16:21:04 -0800213 public MplsLabel interCoLabel() {
214 return interCoLabel;
215 }
216
217 @Override
218 public int hashCode() {
Ray Milkeyeae2b992017-12-15 15:14:06 -0800219 return Objects.hash(this.tunnelId, this.pwMode, this.sdTag, this.pwLabel, this.interCoLabel);
Pier Ventre6b19e482016-11-07 16:21:04 -0800220 }
221
222 @Override
223 public boolean equals(Object o) {
224 if (this == o) {
225 return true;
226 }
227
Pier Ventre6b19e482016-11-07 16:21:04 -0800228 if (o instanceof DefaultL2Tunnel) {
229 DefaultL2Tunnel that = (DefaultL2Tunnel) o;
230 return this.tunnelId == that.tunnelId &&
231 this.pwMode.equals(that.pwMode) &&
232 this.sdTag.equals(that.sdTag) &&
233 this.pwLabel.equals(that.pwLabel) &&
234 this.interCoLabel.equals(that.interCoLabel);
235 }
236
237 return false;
238 }
239
240 @Override
241 public String toString() {
242 return MoreObjects.toStringHelper(this)
243 .add("pwMode", pwMode())
244 .add("sdTag", sdTag())
245 .add("tunnelId", tunnelId())
246 .add("pwLabel", pwLabel())
247 .add("interCoLabel", interCoLabel())
Andreas Pantelopoulos0dec5622018-02-13 15:38:53 -0800248 .add("transportVlan", transportVlan())
Pier Ventre6b19e482016-11-07 16:21:04 -0800249 .toString();
250 }
251
252}