Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | package org.onosproject.net.flow.criteria; |
| 17 | |
| 18 | import java.util.Objects; |
| 19 | |
| 20 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 21 | /** |
| 22 | * Implementation of Tunnel ID criterion. |
| 23 | */ |
| 24 | public class TunnelIdCriterion implements Criterion { |
| 25 | private final long tunnelId; |
| 26 | |
| 27 | /** |
| 28 | * Constructor. |
| 29 | * |
| 30 | * @param tunnelId a Tunnel ID to match(64 bits) |
| 31 | */ |
| 32 | TunnelIdCriterion(long tunnelId) { |
| 33 | this.tunnelId = tunnelId; |
| 34 | } |
| 35 | |
| 36 | @Override |
| 37 | public Type type() { |
| 38 | return Type.TUNNEL_ID; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Gets the Tunnel ID to match. |
| 43 | * |
| 44 | * @return the Tunnel ID to match (64 bits) |
| 45 | */ |
| 46 | public long tunnelId() { |
| 47 | return tunnelId; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public String toString() { |
| 52 | return toStringHelper(type().toString()) |
| 53 | .add("tunnelId", Long.toHexString(tunnelId)) |
| 54 | .toString(); |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public int hashCode() { |
| 59 | return Objects.hash(type().ordinal(), tunnelId); |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public boolean equals(Object obj) { |
| 64 | if (this == obj) { |
| 65 | return true; |
| 66 | } |
| 67 | if (obj instanceof TunnelIdCriterion) { |
| 68 | TunnelIdCriterion that = (TunnelIdCriterion) obj; |
| 69 | return Objects.equals(tunnelId, that.tunnelId) && |
| 70 | Objects.equals(this.type(), that.type()); |
| 71 | } |
| 72 | return false; |
| 73 | } |
| 74 | } |