Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-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.net.flow.criteria; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import com.google.common.base.Objects; |
| 21 | import org.onosproject.net.pi.runtime.PiFieldMatch; |
| 22 | |
| 23 | import java.util.Collection; |
| 24 | import java.util.StringJoiner; |
| 25 | |
| 26 | /** |
| 27 | * Protocol-indepedent criterion. |
| 28 | */ |
| 29 | @Beta |
| 30 | public final class PiCriterion implements Criterion { |
| 31 | |
| 32 | private final Collection<PiFieldMatch> fieldMatches; |
| 33 | |
| 34 | /** |
| 35 | * Creates a new protocol-independent criterion for the given match fields. |
| 36 | * |
| 37 | * @param fieldMatches fields to match |
| 38 | */ |
| 39 | PiCriterion(Collection<PiFieldMatch> fieldMatches) { |
| 40 | this.fieldMatches = fieldMatches; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Returns the match parameters map of this selector. |
| 45 | * |
| 46 | * @return a match parameter map |
| 47 | */ |
| 48 | public Collection<PiFieldMatch> fieldMatches() { |
| 49 | return fieldMatches; |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public Type type() { |
| 54 | return Type.PROTOCOL_INDEPENDENT; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public boolean equals(Object o) { |
| 59 | if (this == o) { |
| 60 | return true; |
| 61 | } |
| 62 | if (o == null || getClass() != o.getClass()) { |
| 63 | return false; |
| 64 | } |
| 65 | PiCriterion that = (PiCriterion) o; |
| 66 | return Objects.equal(fieldMatches, that.fieldMatches); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public int hashCode() { |
| 71 | return Objects.hashCode(fieldMatches); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public String toString() { |
| 76 | StringJoiner stringParams = new StringJoiner(", ", "{", "}"); |
| 77 | fieldMatches.forEach(f -> stringParams.add(f.toString())); |
| 78 | return stringParams.toString(); |
| 79 | } |
| 80 | } |