Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0947d7e | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 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 | */ |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 29 | public class DefaultL2TunnelDescription implements L2TunnelDescription { |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * The l2 tunnel. |
| 33 | */ |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 34 | private L2Tunnel l2Tunnel; |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * The l2 tunnel policy. |
| 38 | */ |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 39 | private L2TunnelPolicy l2TunnelPolicy; |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 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 | */ |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 47 | public DefaultL2TunnelDescription(L2Tunnel l2Tunnel, |
| 48 | L2TunnelPolicy l2TunnelPolicy) { |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 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 | |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 64 | @Override |
| 65 | public L2Tunnel l2Tunnel() { |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 66 | return l2Tunnel; |
| 67 | } |
| 68 | |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 69 | @Override |
| 70 | public L2TunnelPolicy l2TunnelPolicy() { |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 71 | return l2TunnelPolicy; |
| 72 | } |
| 73 | |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 74 | @Override |
| 75 | public void setL2Tunnel(L2Tunnel tunnel) { |
Andreas Pantelopoulos | 0dec562 | 2018-02-13 15:38:53 -0800 | [diff] [blame] | 76 | l2Tunnel = tunnel; |
| 77 | } |
| 78 | |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 79 | @Override |
| 80 | public void setL2TunnelPolicy(L2TunnelPolicy policy) { |
Andreas Pantelopoulos | 0dec562 | 2018-02-13 15:38:53 -0800 | [diff] [blame] | 81 | l2TunnelPolicy = policy; |
| 82 | } |
| 83 | |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 84 | @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 Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 95 | 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 | } |