blob: b5206a309ce7f840f80d821c91eb7dbfb583738b [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 */
29public class DefaultL2TunnelDescription {
30
31 /**
32 * The l2 tunnel.
33 */
34 private DefaultL2Tunnel l2Tunnel;
35
36 /**
37 * The l2 tunnel policy.
38 */
39 private DefaultL2TunnelPolicy l2TunnelPolicy;
40
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 */
47 public DefaultL2TunnelDescription(DefaultL2Tunnel l2Tunnel,
48 DefaultL2TunnelPolicy l2TunnelPolicy) {
49 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
64 /**
65 * Returns the l2 tunnel.
66 *
67 * @return the l2 tunnel
68 */
69 public DefaultL2Tunnel l2Tunnel() {
70 return l2Tunnel;
71 }
72
73 /**
74 * Returns the l2 tunnel policy.
75 *
76 * @return the l2 tunnel policy.
77 */
78 public DefaultL2TunnelPolicy l2TunnelPolicy() {
79 return l2TunnelPolicy;
80 }
81
Andreas Pantelopoulos0dec5622018-02-13 15:38:53 -080082 /**
83 * Sets the l2 tunnel.
84 *
85 * @param tunnel the l2 tunnel to set.
86 */
87 public void setL2Tunnel(DefaultL2Tunnel tunnel) {
88 l2Tunnel = tunnel;
89 }
90
91 /**
92 * Sets the l2 policy.
93 *
94 * @param policy the policy to set.
95 */
96 public void setL2TunnelPolicy(DefaultL2TunnelPolicy policy) {
97 l2TunnelPolicy = policy;
98 }
99
Pier Ventre6b19e482016-11-07 16:21:04 -0800100 @Override
101 public int hashCode() {
102 return Objects.hash(this.l2Tunnel, this.l2TunnelPolicy);
103 }
104
105 @Override
106 public boolean equals(Object o) {
107 if (this == o) {
108 return true;
109 }
110
Pier Ventre6b19e482016-11-07 16:21:04 -0800111 if (o instanceof DefaultL2TunnelDescription) {
112 DefaultL2TunnelDescription that = (DefaultL2TunnelDescription) o;
113 // Equality is based on tunnel id and pw label
114 // which is always the last label.
115 return this.l2Tunnel.equals(that.l2Tunnel) &&
116 this.l2TunnelPolicy.equals(that.l2TunnelPolicy);
117 }
118
119 return false;
120 }
121
122 @Override
123 public String toString() {
124 return MoreObjects.toStringHelper(this)
125 .add("l2Tunnel", l2Tunnel())
126 .add("l2TunnelPolicy", l2TunnelPolicy())
127 .toString();
128 }
129}