blob: 7a479721f2bb543879a1b7b6c6cd24db4ca9b272 [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;
20
21import java.util.Objects;
22
23import static com.google.common.base.Preconditions.checkNotNull;
24
25/**
26 * Helper class to carry the l2 tunnel
27 * and its policy.
28 */
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -080029public class DefaultL2TunnelDescription implements L2TunnelDescription {
Pier Ventre6b19e482016-11-07 16:21:04 -080030
31 /**
32 * The l2 tunnel.
33 */
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -080034 private L2Tunnel l2Tunnel;
Pier Ventre6b19e482016-11-07 16:21:04 -080035
36 /**
37 * The l2 tunnel policy.
38 */
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -080039 private L2TunnelPolicy l2TunnelPolicy;
Pier Ventre6b19e482016-11-07 16:21:04 -080040
41 /**
42 * Creates a l2 tunnel description using the given info.
43 *
44 * @param l2Tunnel the l2 tunnel
45 * @param l2TunnelPolicy the l2 tunnel description
46 */
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -080047 public DefaultL2TunnelDescription(L2Tunnel l2Tunnel,
48 L2TunnelPolicy l2TunnelPolicy) {
Pier Ventre6b19e482016-11-07 16:21:04 -080049 checkNotNull(l2Tunnel);
50 checkNotNull(l2TunnelPolicy);
51
52 this.l2Tunnel = l2Tunnel;
53 this.l2TunnelPolicy = l2TunnelPolicy;
54 }
55
56 /**
57 * Creates an empty l2 tunnel description.
58 */
59 public DefaultL2TunnelDescription() {
60 this.l2Tunnel = null;
61 this.l2TunnelPolicy = null;
62 }
63
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -080064 @Override
65 public L2Tunnel l2Tunnel() {
Pier Ventre6b19e482016-11-07 16:21:04 -080066 return l2Tunnel;
67 }
68
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -080069 @Override
70 public L2TunnelPolicy l2TunnelPolicy() {
Pier Ventre6b19e482016-11-07 16:21:04 -080071 return l2TunnelPolicy;
72 }
73
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -080074 @Override
75 public void setL2Tunnel(L2Tunnel tunnel) {
Andreas Pantelopoulos0dec5622018-02-13 15:38:53 -080076 l2Tunnel = tunnel;
77 }
78
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -080079 @Override
80 public void setL2TunnelPolicy(L2TunnelPolicy policy) {
Andreas Pantelopoulos0dec5622018-02-13 15:38:53 -080081 l2TunnelPolicy = policy;
82 }
83
Pier Ventre6b19e482016-11-07 16:21:04 -080084 @Override
85 public int hashCode() {
86 return Objects.hash(this.l2Tunnel, this.l2TunnelPolicy);
87 }
88
89 @Override
90 public boolean equals(Object o) {
91 if (this == o) {
92 return true;
93 }
94
Pier Ventre6b19e482016-11-07 16:21:04 -080095 if (o instanceof DefaultL2TunnelDescription) {
96 DefaultL2TunnelDescription that = (DefaultL2TunnelDescription) o;
97 // Equality is based on tunnel id and pw label
98 // which is always the last label.
99 return this.l2Tunnel.equals(that.l2Tunnel) &&
100 this.l2TunnelPolicy.equals(that.l2TunnelPolicy);
101 }
102
103 return false;
104 }
105
106 @Override
107 public String toString() {
108 return MoreObjects.toStringHelper(this)
109 .add("l2Tunnel", l2Tunnel())
110 .add("l2TunnelPolicy", l2TunnelPolicy())
111 .toString();
112 }
113}