blob: 47387447af9b3b1423005856b07225a125db0293 [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 */
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -080030public class DefaultL2TunnelPolicy implements L2TunnelPolicy {
Pier Ventre6b19e482016-11-07 16:21:04 -080031
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
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800100 @Override
Pier Ventre6b19e482016-11-07 16:21:04 -0800101 public ConnectPoint cP1() {
102 return cP1;
103 }
104
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800105 @Override
Pier Ventre6b19e482016-11-07 16:21:04 -0800106 public ConnectPoint cP2() {
107 return cP2;
108 }
109
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800110 @Override
Pier Ventre6b19e482016-11-07 16:21:04 -0800111 public VlanId cP1InnerTag() {
112 return cP1InnerTag;
113 }
114
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800115 @Override
Pier Ventre6b19e482016-11-07 16:21:04 -0800116 public VlanId cP1OuterTag() {
117 return cP1OuterTag;
118 }
119
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800120 @Override
Pier Ventre6b19e482016-11-07 16:21:04 -0800121 public VlanId cP2InnerTag() {
122 return cP2InnerTag;
123 }
124
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800125 @Override
Pier Ventre6b19e482016-11-07 16:21:04 -0800126 public VlanId cP2OuterTag() {
127 return cP2OuterTag;
128 }
129
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800130 @Override
Pier Ventre6b19e482016-11-07 16:21:04 -0800131 public long tunnelId() {
132 return this.tunnelId;
133 }
134
135 @Override
136 public int hashCode() {
137 return Objects.hash(tunnelId,
138 cP1,
139 cP2,
140 cP1InnerTag,
141 cP1OuterTag,
142 cP2InnerTag,
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700143 cP2OuterTag
Pier Ventre6b19e482016-11-07 16:21:04 -0800144 );
145 }
146
147 @Override
148 public boolean equals(Object o) {
149 if (this == o) {
150 return true;
151 }
152
153 if (o instanceof DefaultL2TunnelPolicy) {
154 DefaultL2TunnelPolicy that = (DefaultL2TunnelPolicy) o;
155 if (this.tunnelId == that.tunnelId &&
156 this.cP1.equals(that.cP1) &&
157 this.cP2.equals(that.cP2) &&
158 this.cP1InnerTag.equals(that.cP1InnerTag) &&
159 this.cP1OuterTag.equals(that.cP1OuterTag) &&
160 this.cP2InnerTag.equals(that.cP2InnerTag) &&
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700161 this.cP2OuterTag.equals(that.cP2OuterTag)) {
Pier Ventre6b19e482016-11-07 16:21:04 -0800162 return true;
163 }
164 }
165
166 return false;
167 }
168
169 @Override
170 public String toString() {
171 return MoreObjects.toStringHelper(this)
172 .add("tunnelId", tunnelId())
173 .add("cP1", cP1())
174 .add("cP2", cP2())
175 .add("cP1InnerTag", cP1InnerTag())
176 .add("cP1OuterTag", cP1OuterTag())
177 .add("cP2InnerTag", cP2InnerTag())
178 .add("cP2OuterTag", cP2OuterTag())
Pier Ventre6b19e482016-11-07 16:21:04 -0800179 .toString();
180 }
181
182}