Pier Ventre | f34966c | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 3 | * |
| 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 | |
| 17 | package org.onosproject.segmentrouting.pwaas; |
| 18 | |
| 19 | import com.google.common.base.MoreObjects; |
| 20 | |
| 21 | import java.util.Objects; |
| 22 | |
| 23 | import static com.google.common.base.Preconditions.checkNotNull; |
| 24 | |
| 25 | /** |
| 26 | * Helper class to carry the l2 tunnel |
| 27 | * and its policy. |
| 28 | */ |
| 29 | public 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 | |
| 82 | @Override |
| 83 | public int hashCode() { |
| 84 | return Objects.hash(this.l2Tunnel, this.l2TunnelPolicy); |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public boolean equals(Object o) { |
| 89 | if (this == o) { |
| 90 | return true; |
| 91 | } |
| 92 | |
| 93 | if (getClass() != o.getClass()) { |
| 94 | return false; |
| 95 | } |
| 96 | |
| 97 | if (o instanceof DefaultL2TunnelDescription) { |
| 98 | DefaultL2TunnelDescription that = (DefaultL2TunnelDescription) o; |
| 99 | // Equality is based on tunnel id and pw label |
| 100 | // which is always the last label. |
| 101 | return this.l2Tunnel.equals(that.l2Tunnel) && |
| 102 | this.l2TunnelPolicy.equals(that.l2TunnelPolicy); |
| 103 | } |
| 104 | |
| 105 | return false; |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public String toString() { |
| 110 | return MoreObjects.toStringHelper(this) |
| 111 | .add("l2Tunnel", l2Tunnel()) |
| 112 | .add("l2TunnelPolicy", l2TunnelPolicy()) |
| 113 | .toString(); |
| 114 | } |
| 115 | } |