Committed by
Gerrit Code Review
Define a Criterion for OchSginalType
Resolve ONOS-1846 Change-Id: I63462a3e2702c93b1d1c84a324bdbaa351bac633
Showing
4 changed files
with
107 additions
and
0 deletions
... | @@ -25,6 +25,7 @@ import org.onlab.packet.Ip6Address; | ... | @@ -25,6 +25,7 @@ import org.onlab.packet.Ip6Address; |
25 | import org.onlab.packet.MacAddress; | 25 | import org.onlab.packet.MacAddress; |
26 | import org.onlab.packet.MplsLabel; | 26 | import org.onlab.packet.MplsLabel; |
27 | import org.onlab.packet.VlanId; | 27 | import org.onlab.packet.VlanId; |
28 | +import org.onosproject.net.tunnel.OchSignalType; | ||
28 | 29 | ||
29 | /** | 30 | /** |
30 | * Factory class to create various traffic selection criteria. | 31 | * Factory class to create various traffic selection criteria. |
... | @@ -391,6 +392,16 @@ public final class Criteria { | ... | @@ -391,6 +392,16 @@ public final class Criteria { |
391 | return new OpticalSignalTypeCriterion(sigType, Type.OCH_SIGTYPE); | 392 | return new OpticalSignalTypeCriterion(sigType, Type.OCH_SIGTYPE); |
392 | } | 393 | } |
393 | 394 | ||
395 | + /** | ||
396 | + * Create a match on OCh (Optical Channel) signal type. | ||
397 | + * | ||
398 | + * @param signalType OCh signal type | ||
399 | + * @return match criterion | ||
400 | + */ | ||
401 | + public static Criterion matchOchSignalType(OchSignalType signalType) { | ||
402 | + return new OchSignalTypeCriterion(signalType); | ||
403 | + } | ||
404 | + | ||
394 | public static Criterion dummy() { | 405 | public static Criterion dummy() { |
395 | return new DummyCriterion(); | 406 | return new DummyCriterion(); |
396 | } | 407 | } | ... | ... |
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.tunnel.OchSignalType; | ||
20 | + | ||
21 | +import java.util.Objects; | ||
22 | + | ||
23 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
24 | + | ||
25 | +/** | ||
26 | + * Implementation of OCh (Optical Channel) singal type criterion. | ||
27 | + */ | ||
28 | +public class OchSignalTypeCriterion implements Criterion { | ||
29 | + | ||
30 | + private final OchSignalType signalType; | ||
31 | + | ||
32 | + /** | ||
33 | + * Creates a criterion with the specified value. | ||
34 | + * | ||
35 | + * @param signalType OCh signal type | ||
36 | + */ | ||
37 | + OchSignalTypeCriterion(OchSignalType signalType) { | ||
38 | + this.signalType = checkNotNull(signalType); | ||
39 | + } | ||
40 | + | ||
41 | + @Override | ||
42 | + public Type type() { | ||
43 | + return Type.OCH_SIGTYPE; | ||
44 | + } | ||
45 | + | ||
46 | + /** | ||
47 | + * Returns the OCh signal type to match. | ||
48 | + * | ||
49 | + * @return the OCh signal type to match | ||
50 | + */ | ||
51 | + public OchSignalType signalType() { | ||
52 | + return signalType; | ||
53 | + } | ||
54 | + | ||
55 | + @Override | ||
56 | + public int hashCode() { | ||
57 | + return Objects.hash(signalType); | ||
58 | + } | ||
59 | + | ||
60 | + @Override | ||
61 | + public boolean equals(Object obj) { | ||
62 | + if (this == obj) { | ||
63 | + return true; | ||
64 | + } | ||
65 | + if (!(obj instanceof OchSignalTypeCriterion)) { | ||
66 | + return false; | ||
67 | + } | ||
68 | + final OchSignalTypeCriterion that = (OchSignalTypeCriterion) obj; | ||
69 | + return Objects.equals(this.signalType, that.signalType); | ||
70 | + } | ||
71 | + | ||
72 | + @Override | ||
73 | + public String toString() { | ||
74 | + return MoreObjects.toStringHelper(this) | ||
75 | + .add("signalType", signalType) | ||
76 | + .toString(); | ||
77 | + } | ||
78 | +} |
... | @@ -27,6 +27,7 @@ import org.onlab.packet.MplsLabel; | ... | @@ -27,6 +27,7 @@ import org.onlab.packet.MplsLabel; |
27 | import org.onlab.packet.VlanId; | 27 | import org.onlab.packet.VlanId; |
28 | 28 | ||
29 | import com.google.common.testing.EqualsTester; | 29 | import com.google.common.testing.EqualsTester; |
30 | +import org.onosproject.net.tunnel.OchSignalType; | ||
30 | 31 | ||
31 | import static org.hamcrest.MatcherAssert.assertThat; | 32 | import static org.hamcrest.MatcherAssert.assertThat; |
32 | import static org.hamcrest.Matchers.equalTo; | 33 | import static org.hamcrest.Matchers.equalTo; |
... | @@ -220,6 +221,10 @@ public class CriteriaTest { | ... | @@ -220,6 +221,10 @@ public class CriteriaTest { |
220 | Criterion sameAsMatchLambda1 = Criteria.matchLambda(lambda1); | 221 | Criterion sameAsMatchLambda1 = Criteria.matchLambda(lambda1); |
221 | Criterion matchLambda2 = Criteria.matchLambda(lambda2); | 222 | Criterion matchLambda2 = Criteria.matchLambda(lambda2); |
222 | 223 | ||
224 | + Criterion matchOchSignalType1 = Criteria.matchOchSignalType(OchSignalType.FIX_GRID); | ||
225 | + Criterion sameAsMatchOchSignalType1 = Criteria.matchOchSignalType(OchSignalType.FIX_GRID); | ||
226 | + Criterion matchOchSignalType2 = Criteria.matchOchSignalType(OchSignalType.FLEX_GRID); | ||
227 | + | ||
223 | Criterion matchIndexedLambda1 = Criteria.matchLambda(Lambda.indexedLambda(1)); | 228 | Criterion matchIndexedLambda1 = Criteria.matchLambda(Lambda.indexedLambda(1)); |
224 | Criterion sameAsMatchIndexedLambda1 = Criteria.matchLambda(Lambda.indexedLambda(1)); | 229 | Criterion sameAsMatchIndexedLambda1 = Criteria.matchLambda(Lambda.indexedLambda(1)); |
225 | Criterion matchIndexedLambda2 = Criteria.matchLambda(Lambda.indexedLambda(2)); | 230 | Criterion matchIndexedLambda2 = Criteria.matchLambda(Lambda.indexedLambda(2)); |
... | @@ -1057,6 +1062,17 @@ public class CriteriaTest { | ... | @@ -1057,6 +1062,17 @@ public class CriteriaTest { |
1057 | .testEquals(); | 1062 | .testEquals(); |
1058 | } | 1063 | } |
1059 | 1064 | ||
1065 | + /** | ||
1066 | + * Test the equals() method of the OchSignalTypeCriterion class. | ||
1067 | + */ | ||
1068 | + @Test | ||
1069 | + public void testOchSignalTypeCriterionEquals() { | ||
1070 | + new EqualsTester() | ||
1071 | + .addEqualityGroup(matchOchSignalType1, sameAsMatchOchSignalType1) | ||
1072 | + .addEqualityGroup(matchOchSignalType2) | ||
1073 | + .testEquals(); | ||
1074 | + } | ||
1075 | + | ||
1060 | // OpticalSignalTypeCriterion class | 1076 | // OpticalSignalTypeCriterion class |
1061 | 1077 | ||
1062 | /** | 1078 | /** | ... | ... |
... | @@ -102,6 +102,7 @@ import org.onosproject.net.flow.criteria.LambdaCriterion; | ... | @@ -102,6 +102,7 @@ import org.onosproject.net.flow.criteria.LambdaCriterion; |
102 | import org.onosproject.net.flow.criteria.MetadataCriterion; | 102 | import org.onosproject.net.flow.criteria.MetadataCriterion; |
103 | import org.onosproject.net.flow.criteria.MplsCriterion; | 103 | import org.onosproject.net.flow.criteria.MplsCriterion; |
104 | import org.onosproject.net.flow.criteria.OchSignalCriterion; | 104 | import org.onosproject.net.flow.criteria.OchSignalCriterion; |
105 | +import org.onosproject.net.flow.criteria.OchSignalTypeCriterion; | ||
105 | import org.onosproject.net.flow.criteria.OpticalSignalTypeCriterion; | 106 | import org.onosproject.net.flow.criteria.OpticalSignalTypeCriterion; |
106 | import org.onosproject.net.flow.criteria.PortCriterion; | 107 | import org.onosproject.net.flow.criteria.PortCriterion; |
107 | import org.onosproject.net.flow.criteria.SctpPortCriterion; | 108 | import org.onosproject.net.flow.criteria.SctpPortCriterion; |
... | @@ -294,6 +295,7 @@ public final class KryoNamespaces { | ... | @@ -294,6 +295,7 @@ public final class KryoNamespaces { |
294 | LambdaCriterion.class, | 295 | LambdaCriterion.class, |
295 | IndexedLambdaCriterion.class, | 296 | IndexedLambdaCriterion.class, |
296 | OchSignalCriterion.class, | 297 | OchSignalCriterion.class, |
298 | + OchSignalTypeCriterion.class, | ||
297 | OpticalSignalTypeCriterion.class, | 299 | OpticalSignalTypeCriterion.class, |
298 | Criterion.class, | 300 | Criterion.class, |
299 | Criterion.Type.class, | 301 | Criterion.Type.class, | ... | ... |
-
Please register or login to post a comment