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 | |
| 20 | import com.google.common.base.MoreObjects; |
| 21 | import org.onlab.packet.MplsLabel; |
| 22 | import org.onlab.packet.VlanId; |
| 23 | |
| 24 | import java.util.Objects; |
| 25 | |
| 26 | import static com.google.common.base.Preconditions.checkArgument; |
| 27 | import static com.google.common.base.Preconditions.checkNotNull; |
| 28 | |
| 29 | /** |
| 30 | * Implementation of the default l2 tunnel. |
| 31 | */ |
| 32 | public class DefaultL2Tunnel { |
| 33 | |
| 34 | /** |
| 35 | * Mode of the pseudo wire. |
| 36 | */ |
| 37 | private L2Mode pwMode; |
| 38 | /** |
| 39 | * Service delimiting tag. |
| 40 | */ |
| 41 | private VlanId sdTag; |
| 42 | /** |
| 43 | * Tunnel id. |
| 44 | */ |
| 45 | private long tunnelId; |
| 46 | /** |
| 47 | * Pseudo wire label. |
| 48 | */ |
| 49 | private MplsLabel pwLabel; |
| 50 | /** |
| 51 | * Inter-CO label. |
| 52 | */ |
| 53 | private MplsLabel interCoLabel; |
| 54 | |
| 55 | /** |
| 56 | * Creates a inter-co l2 tunnel using the |
| 57 | * supplied parameters. |
| 58 | * |
| 59 | * @param mode the tunnel mode |
| 60 | * @param sdtag the service delimiting tag |
| 61 | * @param tunnelId the tunnel id |
| 62 | * @param pwLabel the pseudo wire label |
| 63 | * @param interCoLabel the inter central office label |
| 64 | */ |
| 65 | public DefaultL2Tunnel(L2Mode mode, |
| 66 | VlanId sdtag, |
| 67 | long tunnelId, |
| 68 | MplsLabel pwLabel, |
| 69 | MplsLabel interCoLabel) { |
| 70 | checkNotNull(mode); |
| 71 | checkArgument(tunnelId > 0); |
| 72 | checkNotNull(pwLabel); |
| 73 | checkNotNull(interCoLabel); |
| 74 | |
| 75 | this.pwMode = mode; |
| 76 | this.sdTag = sdtag; |
| 77 | this.tunnelId = tunnelId; |
| 78 | this.pwLabel = pwLabel; |
| 79 | this.interCoLabel = interCoLabel; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Creates a intra-co l2 tunnel using the |
| 84 | * supplied parameters. |
| 85 | * |
| 86 | * @param mode the tunnel mode |
| 87 | * @param sdtag the service delimiting tag |
| 88 | * @param tunnelId the tunnel id |
| 89 | * @param pwLabel the pseudo wire label |
| 90 | */ |
| 91 | public DefaultL2Tunnel(L2Mode mode, |
| 92 | VlanId sdtag, |
| 93 | long tunnelId, |
| 94 | MplsLabel pwLabel) { |
| 95 | this(mode, sdtag, tunnelId, pwLabel, MplsLabel.mplsLabel(MplsLabel.MAX_MPLS)); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Creates an empty l2 tunnel. |
| 100 | * |
| 101 | **/ |
| 102 | public DefaultL2Tunnel() { |
| 103 | this.pwMode = null; |
| 104 | this.sdTag = null; |
| 105 | this.tunnelId = 0; |
| 106 | this.pwLabel = null; |
| 107 | this.interCoLabel = null; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Returns the mode of the pseudo wire. |
| 112 | * |
| 113 | * @return the pseudo wire mode |
| 114 | */ |
| 115 | public L2Mode pwMode() { |
| 116 | return pwMode; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Returns the service delimitation |
| 121 | * tag. |
| 122 | * |
| 123 | * @return the service delimitation vlan id |
| 124 | */ |
| 125 | public VlanId sdTag() { |
| 126 | return sdTag; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Returns the tunnel id of the pseudo wire. |
| 131 | * |
| 132 | * @return the pseudo wire tunnel id |
| 133 | */ |
| 134 | public long tunnelId() { |
| 135 | return tunnelId; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Returns the pw label. |
| 140 | * |
| 141 | * @return the mpls pw label |
| 142 | */ |
| 143 | public MplsLabel pwLabel() { |
| 144 | return pwLabel; |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Returns the inter-co label. |
| 149 | * |
| 150 | * @return the mpls inter-co label |
| 151 | */ |
| 152 | public MplsLabel interCoLabel() { |
| 153 | return interCoLabel; |
| 154 | } |
| 155 | |
| 156 | @Override |
| 157 | public int hashCode() { |
| 158 | return Objects.hash(this.tunnelId, this.pwLabel); |
| 159 | } |
| 160 | |
| 161 | @Override |
| 162 | public boolean equals(Object o) { |
| 163 | if (this == o) { |
| 164 | return true; |
| 165 | } |
| 166 | |
| 167 | if (getClass() != o.getClass()) { |
| 168 | return false; |
| 169 | } |
| 170 | |
| 171 | if (o instanceof DefaultL2Tunnel) { |
| 172 | DefaultL2Tunnel that = (DefaultL2Tunnel) o; |
| 173 | return this.tunnelId == that.tunnelId && |
| 174 | this.pwMode.equals(that.pwMode) && |
| 175 | this.sdTag.equals(that.sdTag) && |
| 176 | this.pwLabel.equals(that.pwLabel) && |
| 177 | this.interCoLabel.equals(that.interCoLabel); |
| 178 | } |
| 179 | |
| 180 | return false; |
| 181 | } |
| 182 | |
| 183 | @Override |
| 184 | public String toString() { |
| 185 | return MoreObjects.toStringHelper(this) |
| 186 | .add("pwMode", pwMode()) |
| 187 | .add("sdTag", sdTag()) |
| 188 | .add("tunnelId", tunnelId()) |
| 189 | .add("pwLabel", pwLabel()) |
| 190 | .add("interCoLabel", interCoLabel()) |
| 191 | .toString(); |
| 192 | } |
| 193 | |
| 194 | } |