Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -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.net.flow.criteria; |
| 18 | |
| 19 | import org.onosproject.net.DeviceId; |
| 20 | |
| 21 | import java.util.Objects; |
| 22 | |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 23 | /** |
| 24 | * Criterion for implementing selector extensions. |
| 25 | */ |
| 26 | public class ExtensionCriterion implements Criterion { |
| 27 | |
| 28 | private final ExtensionSelector extensionSelector; |
| 29 | private final DeviceId deviceId; |
| 30 | |
| 31 | /** |
| 32 | * Constructor. |
| 33 | * |
| 34 | * @param extensionSelector extension selector |
Jian Li | dfba739 | 2016-01-22 16:46:58 -0800 | [diff] [blame] | 35 | * @param deviceId device identification |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 36 | */ |
| 37 | public ExtensionCriterion(ExtensionSelector extensionSelector, DeviceId deviceId) { |
| 38 | this.extensionSelector = extensionSelector; |
| 39 | this.deviceId = deviceId; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Returns the extension selector. |
| 44 | * |
| 45 | * @return extension selector |
| 46 | */ |
| 47 | public ExtensionSelector extensionSelector() { |
| 48 | return extensionSelector; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Returns the device ID. |
| 53 | * |
| 54 | * @return device ID |
| 55 | */ |
| 56 | public DeviceId deviceId() { |
| 57 | return deviceId; |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public Type type() { |
| 62 | return Type.EXTENSION; |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 67 | return type().toString() + SEPARATOR + deviceId + "/" + extensionSelector; |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public int hashCode() { |
| 72 | return Objects.hash(type().ordinal(), extensionSelector, deviceId); |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public boolean equals(Object obj) { |
| 77 | if (this == obj) { |
| 78 | return true; |
| 79 | } |
| 80 | if (obj instanceof ExtensionCriterion) { |
| 81 | ExtensionCriterion that = (ExtensionCriterion) obj; |
| 82 | return Objects.equals(extensionSelector, that.extensionSelector) && |
| 83 | Objects.equals(deviceId, that.deviceId) && |
| 84 | Objects.equals(this.type(), that.type()); |
| 85 | } |
| 86 | return false; |
| 87 | } |
| 88 | } |