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 | import org.onlab.packet.VlanId; |
| 21 | import org.onosproject.net.ConnectPoint; |
| 22 | |
| 23 | import java.util.Objects; |
| 24 | |
| 25 | import static com.google.common.base.Preconditions.checkNotNull; |
| 26 | |
| 27 | /** |
| 28 | * Implementation of the default l2 tunnel policy. |
| 29 | */ |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 30 | public class DefaultL2TunnelPolicy implements L2TunnelPolicy { |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 31 | |
| 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 Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 60 | |
| 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 Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 72 | */ |
| 73 | public DefaultL2TunnelPolicy(long tunnelId, |
| 74 | ConnectPoint cP1, VlanId cP1InnerTag, VlanId cP1OuterTag, |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 75 | ConnectPoint cP2, VlanId cP2InnerTag, VlanId cP2OuterTag) { |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 76 | 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 Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 83 | } |
| 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 Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 98 | } |
| 99 | |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 100 | @Override |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 101 | public ConnectPoint cP1() { |
| 102 | return cP1; |
| 103 | } |
| 104 | |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 105 | @Override |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 106 | public ConnectPoint cP2() { |
| 107 | return cP2; |
| 108 | } |
| 109 | |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 110 | @Override |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 111 | public VlanId cP1InnerTag() { |
| 112 | return cP1InnerTag; |
| 113 | } |
| 114 | |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 115 | @Override |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 116 | public VlanId cP1OuterTag() { |
| 117 | return cP1OuterTag; |
| 118 | } |
| 119 | |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 120 | @Override |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 121 | public VlanId cP2InnerTag() { |
| 122 | return cP2InnerTag; |
| 123 | } |
| 124 | |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 125 | @Override |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 126 | public VlanId cP2OuterTag() { |
| 127 | return cP2OuterTag; |
| 128 | } |
| 129 | |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 130 | @Override |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 131 | 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 Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 143 | cP2OuterTag |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 144 | ); |
| 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 Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 161 | this.cP2OuterTag.equals(that.cP2OuterTag)) { |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 162 | 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 Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 179 | .toString(); |
| 180 | } |
| 181 | |
| 182 | } |