Pier Ventre | 6b19e48 | 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 | 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 | */ |
| 30 | public class DefaultL2TunnelPolicy { |
| 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; |
| 60 | /** |
| 61 | * Boolean value to indicate if the pseudo wire is port based. |
| 62 | */ |
| 63 | private boolean allVlan; |
| 64 | |
| 65 | /** |
| 66 | * Creates a default l2 tunnel policy using |
| 67 | * the given parameters. |
| 68 | * |
| 69 | * @param tunnelId the tunnel id |
| 70 | * @param cP1 the first connect point |
| 71 | * @param cP1InnerTag the cP1 inner tag |
| 72 | * @param cP1OuterTag the cP1 outer tag |
| 73 | * @param cP2 the second connect point |
| 74 | * @param cP2InnerTag the cP2 inner tag |
| 75 | * @param cP2OuterTag the cP2 outer tag |
| 76 | * @param allVlan if the tunnel is port based or not |
| 77 | */ |
| 78 | public DefaultL2TunnelPolicy(long tunnelId, |
| 79 | ConnectPoint cP1, VlanId cP1InnerTag, VlanId cP1OuterTag, |
| 80 | ConnectPoint cP2, VlanId cP2InnerTag, VlanId cP2OuterTag, |
| 81 | boolean allVlan) { |
| 82 | this.cP1 = checkNotNull(cP1); |
| 83 | this.cP2 = checkNotNull(cP2); |
| 84 | this.tunnelId = tunnelId; |
| 85 | this.cP1InnerTag = cP1InnerTag; |
| 86 | this.cP1OuterTag = cP1OuterTag; |
| 87 | this.cP2InnerTag = cP2InnerTag; |
| 88 | this.cP2OuterTag = cP2OuterTag; |
| 89 | this.allVlan = allVlan; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Returns the first connect point of the policy. |
| 94 | * |
| 95 | * @return first connect point |
| 96 | */ |
| 97 | public ConnectPoint cP1() { |
| 98 | return cP1; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Returns the second connect point of the policy. |
| 103 | * |
| 104 | * @return second connect point |
| 105 | */ |
| 106 | public ConnectPoint cP2() { |
| 107 | return cP2; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Returns the cP1 inner vlan tag of the policy. |
| 112 | * |
| 113 | * @return cP1 inner vlan tag |
| 114 | */ |
| 115 | public VlanId cP1InnerTag() { |
| 116 | return cP1InnerTag; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Returns the cP1 outer vlan tag of the policy. |
| 121 | * |
| 122 | * @return cP1 outer vlan tag |
| 123 | */ |
| 124 | public VlanId cP1OuterTag() { |
| 125 | return cP1OuterTag; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Returns the cP2 inner vlan tag of the policy. |
| 130 | * |
| 131 | * @return cP2 inner vlan tag |
| 132 | */ |
| 133 | public VlanId cP2InnerTag() { |
| 134 | return cP2InnerTag; |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Returns the cP2 outer vlan tag of the policy. |
| 139 | * |
| 140 | * @return cP2 outer vlan tag |
| 141 | */ |
| 142 | public VlanId cP2OuterTag() { |
| 143 | return cP2OuterTag; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Return all vlan value. |
| 148 | * |
| 149 | * @return true, if the pw is port based. False if the traffic is sliced |
| 150 | * through the inner and outer tags |
| 151 | */ |
| 152 | public boolean isAllVlan() { |
| 153 | return allVlan; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Returns the tunnel ID of the policy. |
| 158 | * |
| 159 | * @return Tunnel ID |
| 160 | */ |
| 161 | public long tunnelId() { |
| 162 | return this.tunnelId; |
| 163 | } |
| 164 | |
| 165 | @Override |
| 166 | public int hashCode() { |
| 167 | return Objects.hash(tunnelId, |
| 168 | cP1, |
| 169 | cP2, |
| 170 | cP1InnerTag, |
| 171 | cP1OuterTag, |
| 172 | cP2InnerTag, |
| 173 | cP2OuterTag, |
| 174 | allVlan |
| 175 | ); |
| 176 | } |
| 177 | |
| 178 | @Override |
| 179 | public boolean equals(Object o) { |
| 180 | if (this == o) { |
| 181 | return true; |
| 182 | } |
| 183 | |
| 184 | if (o instanceof DefaultL2TunnelPolicy) { |
| 185 | DefaultL2TunnelPolicy that = (DefaultL2TunnelPolicy) o; |
| 186 | if (this.tunnelId == that.tunnelId && |
| 187 | this.cP1.equals(that.cP1) && |
| 188 | this.cP2.equals(that.cP2) && |
| 189 | this.cP1InnerTag.equals(that.cP1InnerTag) && |
| 190 | this.cP1OuterTag.equals(that.cP1OuterTag) && |
| 191 | this.cP2InnerTag.equals(that.cP2InnerTag) && |
| 192 | this.cP2OuterTag.equals(that.cP2OuterTag) && |
| 193 | this.allVlan == that.allVlan) { |
| 194 | return true; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | return false; |
| 199 | } |
| 200 | |
| 201 | @Override |
| 202 | public String toString() { |
| 203 | return MoreObjects.toStringHelper(this) |
| 204 | .add("tunnelId", tunnelId()) |
| 205 | .add("cP1", cP1()) |
| 206 | .add("cP2", cP2()) |
| 207 | .add("cP1InnerTag", cP1InnerTag()) |
| 208 | .add("cP1OuterTag", cP1OuterTag()) |
| 209 | .add("cP2InnerTag", cP2InnerTag()) |
| 210 | .add("cP2OuterTag", cP2OuterTag()) |
| 211 | .add("allVlan", isAllVlan()) |
| 212 | .toString(); |
| 213 | } |
| 214 | |
| 215 | } |