Committed by
Gerrit Code Review
Define a Criterion for IndexedLambda
Resolve ONOS-1845 Change-Id: Ic6f0ea2572e83c10444d7452debfd302149dc994
Showing
4 changed files
with
99 additions
and
1 deletions
| ... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.net.flow.criteria; | 16 | package org.onosproject.net.flow.criteria; |
| 17 | 17 | ||
| 18 | +import org.onosproject.net.IndexedLambda; | ||
| 18 | import org.onosproject.net.Lambda; | 19 | import org.onosproject.net.Lambda; |
| 19 | import org.onosproject.net.OchSignal; | 20 | import org.onosproject.net.OchSignal; |
| 20 | import org.onosproject.net.PortNumber; | 21 | import org.onosproject.net.PortNumber; |
| ... | @@ -359,6 +360,7 @@ public final class Criteria { | ... | @@ -359,6 +360,7 @@ public final class Criteria { |
| 359 | * @param lambda lambda to match on (16 bits unsigned integer) | 360 | * @param lambda lambda to match on (16 bits unsigned integer) |
| 360 | * @return match criterion | 361 | * @return match criterion |
| 361 | */ | 362 | */ |
| 363 | + @Deprecated | ||
| 362 | public static Criterion matchLambda(int lambda) { | 364 | public static Criterion matchLambda(int lambda) { |
| 363 | return new LambdaCriterion(lambda, Type.OCH_SIGID); | 365 | return new LambdaCriterion(lambda, Type.OCH_SIGID); |
| 364 | } | 366 | } |
| ... | @@ -370,7 +372,9 @@ public final class Criteria { | ... | @@ -370,7 +372,9 @@ public final class Criteria { |
| 370 | * @return match criterion | 372 | * @return match criterion |
| 371 | */ | 373 | */ |
| 372 | public static Criterion matchLambda(Lambda lambda) { | 374 | public static Criterion matchLambda(Lambda lambda) { |
| 373 | - if (lambda instanceof OchSignal) { | 375 | + if (lambda instanceof IndexedLambda) { |
| 376 | + return new IndexedLambdaCriterion((IndexedLambda) lambda); | ||
| 377 | + } else if (lambda instanceof OchSignal) { | ||
| 374 | return new OchSignalCriterion((OchSignal) lambda); | 378 | return new OchSignalCriterion((OchSignal) lambda); |
| 375 | } else { | 379 | } else { |
| 376 | throw new UnsupportedOperationException(String.format("Unsupported type of Lambda: %s", lambda)); | 380 | throw new UnsupportedOperationException(String.format("Unsupported type of Lambda: %s", lambda)); | ... | ... |
| 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 com.google.common.base.MoreObjects; | ||
| 19 | +import org.onosproject.net.IndexedLambda; | ||
| 20 | + | ||
| 21 | +import java.util.Objects; | ||
| 22 | + | ||
| 23 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * Implementation of indexed lambda criterion. | ||
| 27 | + */ | ||
| 28 | +public class IndexedLambdaCriterion implements Criterion { | ||
| 29 | + | ||
| 30 | + private final IndexedLambda lambda; | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * Creates a criterion with the specified value. | ||
| 34 | + * | ||
| 35 | + * @param lambda lambda index number | ||
| 36 | + */ | ||
| 37 | + IndexedLambdaCriterion(IndexedLambda lambda) { | ||
| 38 | + this.lambda = checkNotNull(lambda); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + @Override | ||
| 42 | + public Type type() { | ||
| 43 | + // TODO: consider defining a new specific type | ||
| 44 | + // Now OCH_SIGID is used due to compatibility concerns | ||
| 45 | + return Type.OCH_SIGID; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * Returns the indexed lambda to match. | ||
| 50 | + * | ||
| 51 | + * @return the indexed lambda to match | ||
| 52 | + */ | ||
| 53 | + public IndexedLambda lambda() { | ||
| 54 | + return lambda; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + @Override | ||
| 58 | + public int hashCode() { | ||
| 59 | + return Objects.hash(lambda); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + @Override | ||
| 63 | + public boolean equals(Object obj) { | ||
| 64 | + if (this == obj) { | ||
| 65 | + return true; | ||
| 66 | + } | ||
| 67 | + if (!(obj instanceof IndexedLambdaCriterion)) { | ||
| 68 | + return false; | ||
| 69 | + } | ||
| 70 | + final IndexedLambdaCriterion that = (IndexedLambdaCriterion) obj; | ||
| 71 | + return Objects.equals(this.lambda, that.lambda); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + @Override | ||
| 75 | + public String toString() { | ||
| 76 | + return MoreObjects.toStringHelper(this) | ||
| 77 | + .add("lambda", lambda) | ||
| 78 | + .toString(); | ||
| 79 | + } | ||
| 80 | +} |
| ... | @@ -220,6 +220,10 @@ public class CriteriaTest { | ... | @@ -220,6 +220,10 @@ public class CriteriaTest { |
| 220 | Criterion sameAsMatchLambda1 = Criteria.matchLambda(lambda1); | 220 | Criterion sameAsMatchLambda1 = Criteria.matchLambda(lambda1); |
| 221 | Criterion matchLambda2 = Criteria.matchLambda(lambda2); | 221 | Criterion matchLambda2 = Criteria.matchLambda(lambda2); |
| 222 | 222 | ||
| 223 | + Criterion matchIndexedLambda1 = Criteria.matchLambda(Lambda.indexedLambda(1)); | ||
| 224 | + Criterion sameAsMatchIndexedLambda1 = Criteria.matchLambda(Lambda.indexedLambda(1)); | ||
| 225 | + Criterion matchIndexedLambda2 = Criteria.matchLambda(Lambda.indexedLambda(2)); | ||
| 226 | + | ||
| 223 | short signalLambda1 = 1; | 227 | short signalLambda1 = 1; |
| 224 | short signalLambda2 = 2; | 228 | short signalLambda2 = 2; |
| 225 | Criterion matchSignalLambda1 = Criteria.matchOpticalSignalType(signalLambda1); | 229 | Criterion matchSignalLambda1 = Criteria.matchOpticalSignalType(signalLambda1); |
| ... | @@ -1038,6 +1042,14 @@ public class CriteriaTest { | ... | @@ -1038,6 +1042,14 @@ public class CriteriaTest { |
| 1038 | } | 1042 | } |
| 1039 | 1043 | ||
| 1040 | @Test | 1044 | @Test |
| 1045 | + public void testIndexedLambdaCriterionEquals() { | ||
| 1046 | + new EqualsTester() | ||
| 1047 | + .addEqualityGroup(matchIndexedLambda1, sameAsMatchIndexedLambda1) | ||
| 1048 | + .addEqualityGroup(matchIndexedLambda2) | ||
| 1049 | + .testEquals(); | ||
| 1050 | + } | ||
| 1051 | + | ||
| 1052 | + @Test | ||
| 1041 | public void testOchSignalCriterionEquals() { | 1053 | public void testOchSignalCriterionEquals() { |
| 1042 | new EqualsTester() | 1054 | new EqualsTester() |
| 1043 | .addEqualityGroup(matchOchSignal1, sameAsMatchOchSignal1) | 1055 | .addEqualityGroup(matchOchSignal1, sameAsMatchOchSignal1) | ... | ... |
| ... | @@ -97,6 +97,7 @@ import org.onosproject.net.flow.criteria.IcmpCodeCriterion; | ... | @@ -97,6 +97,7 @@ import org.onosproject.net.flow.criteria.IcmpCodeCriterion; |
| 97 | import org.onosproject.net.flow.criteria.IcmpTypeCriterion; | 97 | import org.onosproject.net.flow.criteria.IcmpTypeCriterion; |
| 98 | import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion; | 98 | import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion; |
| 99 | import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion; | 99 | import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion; |
| 100 | +import org.onosproject.net.flow.criteria.IndexedLambdaCriterion; | ||
| 100 | import org.onosproject.net.flow.criteria.LambdaCriterion; | 101 | import org.onosproject.net.flow.criteria.LambdaCriterion; |
| 101 | import org.onosproject.net.flow.criteria.MetadataCriterion; | 102 | import org.onosproject.net.flow.criteria.MetadataCriterion; |
| 102 | import org.onosproject.net.flow.criteria.MplsCriterion; | 103 | import org.onosproject.net.flow.criteria.MplsCriterion; |
| ... | @@ -291,6 +292,7 @@ public final class KryoNamespaces { | ... | @@ -291,6 +292,7 @@ public final class KryoNamespaces { |
| 291 | MplsCriterion.class, | 292 | MplsCriterion.class, |
| 292 | IPv6ExthdrFlagsCriterion.class, | 293 | IPv6ExthdrFlagsCriterion.class, |
| 293 | LambdaCriterion.class, | 294 | LambdaCriterion.class, |
| 295 | + IndexedLambdaCriterion.class, | ||
| 294 | OchSignalCriterion.class, | 296 | OchSignalCriterion.class, |
| 295 | OpticalSignalTypeCriterion.class, | 297 | OpticalSignalTypeCriterion.class, |
| 296 | Criterion.class, | 298 | Criterion.class, | ... | ... |
-
Please register or login to post a comment