blob: aa7d99c608eb49b0510a85615b3a7cf46b70a5bf [file] [log] [blame]
Pier Ventref34966c2016-11-07 16:21:04 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Pier Ventref34966c2016-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;
23
24import java.util.Objects;
25
26import static com.google.common.base.Preconditions.checkArgument;
27import static com.google.common.base.Preconditions.checkNotNull;
28
29/**
30 * Implementation of the default l2 tunnel.
31 */
32public class DefaultL2Tunnel {
33
34 /**
35 * Mode of the pseudo wire.
36 */
37 private L2Mode pwMode;
38 /**
39 * Service delimiting tag.
40 */
41 private VlanId sdTag;
42 /**
43 * Tunnel id.
44 */
45 private long tunnelId;
46 /**
47 * Pseudo wire label.
48 */
49 private MplsLabel pwLabel;
50 /**
51 * Inter-CO label.
52 */
53 private MplsLabel interCoLabel;
54
55 /**
56 * Creates a inter-co l2 tunnel using the
57 * supplied parameters.
58 *
59 * @param mode the tunnel mode
60 * @param sdtag the service delimiting tag
61 * @param tunnelId the tunnel id
62 * @param pwLabel the pseudo wire label
63 * @param interCoLabel the inter central office label
64 */
65 public DefaultL2Tunnel(L2Mode mode,
66 VlanId sdtag,
67 long tunnelId,
68 MplsLabel pwLabel,
69 MplsLabel interCoLabel) {
70 checkNotNull(mode);
71 checkArgument(tunnelId > 0);
72 checkNotNull(pwLabel);
73 checkNotNull(interCoLabel);
74
75 this.pwMode = mode;
76 this.sdTag = sdtag;
77 this.tunnelId = tunnelId;
78 this.pwLabel = pwLabel;
79 this.interCoLabel = interCoLabel;
80 }
81
82 /**
83 * Creates a intra-co l2 tunnel using the
84 * supplied parameters.
85 *
86 * @param mode the tunnel mode
87 * @param sdtag the service delimiting tag
88 * @param tunnelId the tunnel id
89 * @param pwLabel the pseudo wire label
90 */
91 public DefaultL2Tunnel(L2Mode mode,
92 VlanId sdtag,
93 long tunnelId,
94 MplsLabel pwLabel) {
95 this(mode, sdtag, tunnelId, pwLabel, MplsLabel.mplsLabel(MplsLabel.MAX_MPLS));
96 }
97
98 /**
99 * Creates an empty l2 tunnel.
100 *
101 **/
102 public DefaultL2Tunnel() {
103 this.pwMode = null;
104 this.sdTag = null;
105 this.tunnelId = 0;
106 this.pwLabel = null;
107 this.interCoLabel = null;
108 }
109
110 /**
111 * Returns the mode of the pseudo wire.
112 *
113 * @return the pseudo wire mode
114 */
115 public L2Mode pwMode() {
116 return pwMode;
117 }
118
119 /**
120 * Returns the service delimitation
121 * tag.
122 *
123 * @return the service delimitation vlan id
124 */
125 public VlanId sdTag() {
126 return sdTag;
127 }
128
129 /**
130 * Returns the tunnel id of the pseudo wire.
131 *
132 * @return the pseudo wire tunnel id
133 */
134 public long tunnelId() {
135 return tunnelId;
136 }
137
138 /**
139 * Returns the pw label.
140 *
141 * @return the mpls pw label
142 */
143 public MplsLabel pwLabel() {
144 return pwLabel;
145 }
146
147 /**
148 * Returns the inter-co label.
149 *
150 * @return the mpls inter-co label
151 */
152 public MplsLabel interCoLabel() {
153 return interCoLabel;
154 }
155
156 @Override
157 public int hashCode() {
Ray Milkey5a45bbc2017-12-15 15:14:06 -0800158 return Objects.hash(this.tunnelId, this.pwMode, this.sdTag, this.pwLabel, this.interCoLabel);
Pier Ventref34966c2016-11-07 16:21:04 -0800159 }
160
161 @Override
162 public boolean equals(Object o) {
163 if (this == o) {
164 return true;
165 }
166
Pier Ventref34966c2016-11-07 16:21:04 -0800167 if (o instanceof DefaultL2Tunnel) {
168 DefaultL2Tunnel that = (DefaultL2Tunnel) o;
169 return this.tunnelId == that.tunnelId &&
170 this.pwMode.equals(that.pwMode) &&
171 this.sdTag.equals(that.sdTag) &&
172 this.pwLabel.equals(that.pwLabel) &&
173 this.interCoLabel.equals(that.interCoLabel);
174 }
175
176 return false;
177 }
178
179 @Override
180 public String toString() {
181 return MoreObjects.toStringHelper(this)
182 .add("pwMode", pwMode())
183 .add("sdTag", sdTag())
184 .add("tunnelId", tunnelId())
185 .add("pwLabel", pwLabel())
186 .add("interCoLabel", interCoLabel())
187 .toString();
188 }
189
190}