blob: 64923bb94617aacc7c46d342af0742fd1986e3e0 [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 */
35public 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 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 */
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 Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700168 * 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 Pantelopoulos0dec5622018-02-13 15:38:53 -0800177 * 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 Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700186 * Returns the used path of the pseudowire.
187 *
188 * @return pathUsed
189 */
190 public List<Link> pathUsed() {
191 return pathUsed;
192 }
193
Andreas Pantelopoulos0dec5622018-02-13 15:38:53 -0800194 public VlanId transportVlan() {
195 return transportVlan;
196 }
197
198
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700199 /**
Pier Ventre6b19e482016-11-07 16:21:04 -0800200 * 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 Milkeyeae2b992017-12-15 15:14:06 -0800210 return Objects.hash(this.tunnelId, this.pwMode, this.sdTag, this.pwLabel, this.interCoLabel);
Pier Ventre6b19e482016-11-07 16:21:04 -0800211 }
212
213 @Override
214 public boolean equals(Object o) {
215 if (this == o) {
216 return true;
217 }
218
Pier Ventre6b19e482016-11-07 16:21:04 -0800219 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 Pantelopoulos0dec5622018-02-13 15:38:53 -0800239 .add("transportVlan", transportVlan())
Pier Ventre6b19e482016-11-07 16:21:04 -0800240 .toString();
241 }
242
243}