blob: ac52f3e264f018444c6b2630739c35f7282f4844 [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
19import com.google.common.base.MoreObjects;
20import org.onlab.packet.VlanId;
21import org.onosproject.net.ConnectPoint;
22
23import java.util.Objects;
24
25import static com.google.common.base.Preconditions.checkNotNull;
26
27/**
28 * Implementation of the default l2 tunnel policy.
29 */
30public class DefaultL2TunnelPolicy {
31
32 /**
33 * Id of the tunnel associated to this policy.
34 */
35 private long tunnelId;
36 /**
37 * First connect point.
38 */
39 private ConnectPoint cP1;
40 /**
41 * Second connect point.
42 */
43 private ConnectPoint cP2;
44 /**
45 * cP1 inner vlan tag. Used in QinQ packets.
46 */
47 private VlanId cP1InnerTag;
48 /**
49 * cP1 outer vlan tag.
50 */
51 private VlanId cP1OuterTag;
52 /**
53 * cP2 inner vlan tag. Used in QinQ packets.
54 */
55 private VlanId cP2InnerTag;
56 /**
57 * cP2 outer vlan tag.
58 */
59 private VlanId cP2OuterTag;
Pier Ventre6b19e482016-11-07 16:21:04 -080060
61 /**
62 * Creates a default l2 tunnel policy using
63 * the given parameters.
64 *
65 * @param tunnelId the tunnel id
66 * @param cP1 the first connect point
67 * @param cP1InnerTag the cP1 inner tag
68 * @param cP1OuterTag the cP1 outer tag
69 * @param cP2 the second connect point
70 * @param cP2InnerTag the cP2 inner tag
71 * @param cP2OuterTag the cP2 outer tag
Pier Ventre6b19e482016-11-07 16:21:04 -080072 */
73 public DefaultL2TunnelPolicy(long tunnelId,
74 ConnectPoint cP1, VlanId cP1InnerTag, VlanId cP1OuterTag,
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070075 ConnectPoint cP2, VlanId cP2InnerTag, VlanId cP2OuterTag) {
Pier Ventre6b19e482016-11-07 16:21:04 -080076 this.cP1 = checkNotNull(cP1);
77 this.cP2 = checkNotNull(cP2);
78 this.tunnelId = tunnelId;
79 this.cP1InnerTag = cP1InnerTag;
80 this.cP1OuterTag = cP1OuterTag;
81 this.cP2InnerTag = cP2InnerTag;
82 this.cP2OuterTag = cP2OuterTag;
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -070083 }
84
85 /**
86 * Creates a default l2 policy given the provided policy.
87 * @param policy L2policy to replicate
88 */
89 public DefaultL2TunnelPolicy(DefaultL2TunnelPolicy policy) {
90
91 this.cP1 = policy.cP1;
92 this.cP2 = policy.cP2;
93 this.tunnelId = policy.tunnelId;
94 this.cP1InnerTag = policy.cP1InnerTag;
95 this.cP1OuterTag = policy.cP1OuterTag;
96 this.cP2InnerTag = policy.cP2InnerTag;
97 this.cP2OuterTag = policy.cP2OuterTag;
Pier Ventre6b19e482016-11-07 16:21:04 -080098 }
99
100 /**
101 * Returns the first connect point of the policy.
102 *
103 * @return first connect point
104 */
105 public ConnectPoint cP1() {
106 return cP1;
107 }
108
109 /**
110 * Returns the second connect point of the policy.
111 *
112 * @return second connect point
113 */
114 public ConnectPoint cP2() {
115 return cP2;
116 }
117
118 /**
119 * Returns the cP1 inner vlan tag of the policy.
120 *
121 * @return cP1 inner vlan tag
122 */
123 public VlanId cP1InnerTag() {
124 return cP1InnerTag;
125 }
126
127 /**
128 * Returns the cP1 outer vlan tag of the policy.
129 *
130 * @return cP1 outer vlan tag
131 */
132 public VlanId cP1OuterTag() {
133 return cP1OuterTag;
134 }
135
136 /**
137 * Returns the cP2 inner vlan tag of the policy.
138 *
139 * @return cP2 inner vlan tag
140 */
141 public VlanId cP2InnerTag() {
142 return cP2InnerTag;
143 }
144
145 /**
146 * Returns the cP2 outer vlan tag of the policy.
147 *
148 * @return cP2 outer vlan tag
149 */
150 public VlanId cP2OuterTag() {
151 return cP2OuterTag;
152 }
153
154 /**
Pier Ventre6b19e482016-11-07 16:21:04 -0800155 * Returns the tunnel ID of the policy.
156 *
157 * @return Tunnel ID
158 */
159 public long tunnelId() {
160 return this.tunnelId;
161 }
162
163 @Override
164 public int hashCode() {
165 return Objects.hash(tunnelId,
166 cP1,
167 cP2,
168 cP1InnerTag,
169 cP1OuterTag,
170 cP2InnerTag,
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700171 cP2OuterTag
Pier Ventre6b19e482016-11-07 16:21:04 -0800172 );
173 }
174
175 @Override
176 public boolean equals(Object o) {
177 if (this == o) {
178 return true;
179 }
180
181 if (o instanceof DefaultL2TunnelPolicy) {
182 DefaultL2TunnelPolicy that = (DefaultL2TunnelPolicy) o;
183 if (this.tunnelId == that.tunnelId &&
184 this.cP1.equals(that.cP1) &&
185 this.cP2.equals(that.cP2) &&
186 this.cP1InnerTag.equals(that.cP1InnerTag) &&
187 this.cP1OuterTag.equals(that.cP1OuterTag) &&
188 this.cP2InnerTag.equals(that.cP2InnerTag) &&
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700189 this.cP2OuterTag.equals(that.cP2OuterTag)) {
Pier Ventre6b19e482016-11-07 16:21:04 -0800190 return true;
191 }
192 }
193
194 return false;
195 }
196
197 @Override
198 public String toString() {
199 return MoreObjects.toStringHelper(this)
200 .add("tunnelId", tunnelId())
201 .add("cP1", cP1())
202 .add("cP2", cP2())
203 .add("cP1InnerTag", cP1InnerTag())
204 .add("cP1OuterTag", cP1OuterTag())
205 .add("cP2InnerTag", cP2InnerTag())
206 .add("cP2OuterTag", cP2OuterTag())
Pier Ventre6b19e482016-11-07 16:21:04 -0800207 .toString();
208 }
209
210}