Committed by
Gerrit Code Review
Define a Criterion for OchSignal
Resolve ONOS-1844 Change-Id: I775a64ad6d6d3f1a046a6f7895a412c71c17ff16
Showing
4 changed files
with
117 additions
and
0 deletions
... | @@ -15,6 +15,8 @@ | ... | @@ -15,6 +15,8 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.flow.criteria; | 16 | package org.onosproject.net.flow.criteria; |
17 | 17 | ||
18 | +import org.onosproject.net.Lambda; | ||
19 | +import org.onosproject.net.OchSignal; | ||
18 | import org.onosproject.net.PortNumber; | 20 | import org.onosproject.net.PortNumber; |
19 | import org.onosproject.net.flow.criteria.Criterion.Type; | 21 | import org.onosproject.net.flow.criteria.Criterion.Type; |
20 | import org.onlab.packet.IpPrefix; | 22 | import org.onlab.packet.IpPrefix; |
... | @@ -362,6 +364,20 @@ public final class Criteria { | ... | @@ -362,6 +364,20 @@ public final class Criteria { |
362 | } | 364 | } |
363 | 365 | ||
364 | /** | 366 | /** |
367 | + * Creates a match on lambda using the specified value. | ||
368 | + * | ||
369 | + * @param lambda lambda | ||
370 | + * @return match criterion | ||
371 | + */ | ||
372 | + public static Criterion matchLambda(Lambda lambda) { | ||
373 | + if (lambda instanceof OchSignal) { | ||
374 | + return new OchSignalCriterion((OchSignal) lambda); | ||
375 | + } else { | ||
376 | + throw new UnsupportedOperationException(String.format("Unsupported type of Lambda: %s", lambda)); | ||
377 | + } | ||
378 | + } | ||
379 | + | ||
380 | + /** | ||
365 | * Creates a match on optical signal type using the specified value. | 381 | * Creates a match on optical signal type using the specified value. |
366 | * | 382 | * |
367 | * @param sigType optical signal type (8 bits unsigned integer) | 383 | * @param sigType optical signal type (8 bits unsigned integer) | ... | ... |
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.OchSignal; | ||
20 | + | ||
21 | +import java.util.Objects; | ||
22 | + | ||
23 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
24 | + | ||
25 | +/** | ||
26 | + * Implementation of OCh (Optical Channel) signal criterion. | ||
27 | + * This criterion is based on the specification of "OFPXMT_EXP_OCH_SIGID" in | ||
28 | + * Open Networking Foundation "Optical Transport Protocol Extension Version 1.0", but | ||
29 | + * defined in protocol agnostic way. | ||
30 | + */ | ||
31 | +public final class OchSignalCriterion implements Criterion { | ||
32 | + | ||
33 | + private final OchSignal lambda; | ||
34 | + | ||
35 | + /** | ||
36 | + * Create an instance with the specified OCh signal. | ||
37 | + * | ||
38 | + * @param lambda OCh signal | ||
39 | + */ | ||
40 | + OchSignalCriterion(OchSignal lambda) { | ||
41 | + this.lambda = checkNotNull(lambda); | ||
42 | + } | ||
43 | + | ||
44 | + @Override | ||
45 | + public Type type() { | ||
46 | + return Type.OCH_SIGID; | ||
47 | + } | ||
48 | + | ||
49 | + /** | ||
50 | + * Returns the OCh signal to match. | ||
51 | + * | ||
52 | + * @return the OCh signal to match | ||
53 | + */ | ||
54 | + public OchSignal lambda() { | ||
55 | + return lambda; | ||
56 | + } | ||
57 | + | ||
58 | + @Override | ||
59 | + public int hashCode() { | ||
60 | + return Objects.hash(lambda); | ||
61 | + } | ||
62 | + | ||
63 | + @Override | ||
64 | + public boolean equals(Object obj) { | ||
65 | + if (this == obj) { | ||
66 | + return true; | ||
67 | + } | ||
68 | + if (!(obj instanceof OchSignalCriterion)) { | ||
69 | + return false; | ||
70 | + } | ||
71 | + final OchSignalCriterion that = (OchSignalCriterion) obj; | ||
72 | + return Objects.equals(this.lambda, that.lambda); | ||
73 | + } | ||
74 | + | ||
75 | + @Override | ||
76 | + public String toString() { | ||
77 | + return MoreObjects.toStringHelper(this) | ||
78 | + .add("lambda", lambda) | ||
79 | + .toString(); | ||
80 | + } | ||
81 | +} |
... | @@ -16,6 +16,9 @@ | ... | @@ -16,6 +16,9 @@ |
16 | package org.onosproject.net.flow.criteria; | 16 | package org.onosproject.net.flow.criteria; |
17 | 17 | ||
18 | import org.junit.Test; | 18 | import org.junit.Test; |
19 | +import org.onosproject.net.ChannelSpacing; | ||
20 | +import org.onosproject.net.GridType; | ||
21 | +import org.onosproject.net.Lambda; | ||
19 | import org.onosproject.net.PortNumber; | 22 | import org.onosproject.net.PortNumber; |
20 | import org.onlab.packet.IpPrefix; | 23 | import org.onlab.packet.IpPrefix; |
21 | import org.onlab.packet.Ip6Address; | 24 | import org.onlab.packet.Ip6Address; |
... | @@ -223,6 +226,13 @@ public class CriteriaTest { | ... | @@ -223,6 +226,13 @@ public class CriteriaTest { |
223 | Criterion sameAsMatchSignalLambda1 = Criteria.matchOpticalSignalType(signalLambda1); | 226 | Criterion sameAsMatchSignalLambda1 = Criteria.matchOpticalSignalType(signalLambda1); |
224 | Criterion matchSignalLambda2 = Criteria.matchOpticalSignalType(signalLambda2); | 227 | Criterion matchSignalLambda2 = Criteria.matchOpticalSignalType(signalLambda2); |
225 | 228 | ||
229 | + Criterion matchOchSignal1 = | ||
230 | + Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8)); | ||
231 | + Criterion sameAsMatchOchSignal1 = | ||
232 | + Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8)); | ||
233 | + Criterion matchOchSignal2 = | ||
234 | + Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 4, 8)); | ||
235 | + | ||
226 | /** | 236 | /** |
227 | * Checks that a Criterion object has the proper type, and then converts | 237 | * Checks that a Criterion object has the proper type, and then converts |
228 | * it to the proper type. | 238 | * it to the proper type. |
... | @@ -1027,6 +1037,14 @@ public class CriteriaTest { | ... | @@ -1027,6 +1037,14 @@ public class CriteriaTest { |
1027 | .testEquals(); | 1037 | .testEquals(); |
1028 | } | 1038 | } |
1029 | 1039 | ||
1040 | + @Test | ||
1041 | + public void testOchSignalCriterionEquals() { | ||
1042 | + new EqualsTester() | ||
1043 | + .addEqualityGroup(matchOchSignal1, sameAsMatchOchSignal1) | ||
1044 | + .addEqualityGroup(matchOchSignal2) | ||
1045 | + .testEquals(); | ||
1046 | + } | ||
1047 | + | ||
1030 | // OpticalSignalTypeCriterion class | 1048 | // OpticalSignalTypeCriterion class |
1031 | 1049 | ||
1032 | /** | 1050 | /** | ... | ... |
... | @@ -100,6 +100,7 @@ import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion; | ... | @@ -100,6 +100,7 @@ import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion; |
100 | import org.onosproject.net.flow.criteria.LambdaCriterion; | 100 | import org.onosproject.net.flow.criteria.LambdaCriterion; |
101 | import org.onosproject.net.flow.criteria.MetadataCriterion; | 101 | import org.onosproject.net.flow.criteria.MetadataCriterion; |
102 | import org.onosproject.net.flow.criteria.MplsCriterion; | 102 | import org.onosproject.net.flow.criteria.MplsCriterion; |
103 | +import org.onosproject.net.flow.criteria.OchSignalCriterion; | ||
103 | import org.onosproject.net.flow.criteria.OpticalSignalTypeCriterion; | 104 | import org.onosproject.net.flow.criteria.OpticalSignalTypeCriterion; |
104 | import org.onosproject.net.flow.criteria.PortCriterion; | 105 | import org.onosproject.net.flow.criteria.PortCriterion; |
105 | import org.onosproject.net.flow.criteria.SctpPortCriterion; | 106 | import org.onosproject.net.flow.criteria.SctpPortCriterion; |
... | @@ -290,6 +291,7 @@ public final class KryoNamespaces { | ... | @@ -290,6 +291,7 @@ public final class KryoNamespaces { |
290 | MplsCriterion.class, | 291 | MplsCriterion.class, |
291 | IPv6ExthdrFlagsCriterion.class, | 292 | IPv6ExthdrFlagsCriterion.class, |
292 | LambdaCriterion.class, | 293 | LambdaCriterion.class, |
294 | + OchSignalCriterion.class, | ||
293 | OpticalSignalTypeCriterion.class, | 295 | OpticalSignalTypeCriterion.class, |
294 | Criterion.class, | 296 | Criterion.class, |
295 | Criterion.Type.class, | 297 | Criterion.Type.class, | ... | ... |
-
Please register or login to post a comment