Committed by
Gerrit Code Review
[ONOS-3513] Implement PBB I-SID Criterion and test case to Southbound
Change-Id: Ic6836cb7df1eb2d8b871b85029a1a8e31add1289
Showing
4 changed files
with
119 additions
and
0 deletions
... | @@ -581,6 +581,16 @@ public final class Criteria { | ... | @@ -581,6 +581,16 @@ public final class Criteria { |
581 | } | 581 | } |
582 | 582 | ||
583 | /** | 583 | /** |
584 | + * Creates a match on PBB I-SID field using the specific value. | ||
585 | + * | ||
586 | + * @param pbbIsid PBB I-SID | ||
587 | + * @return match criterion | ||
588 | + */ | ||
589 | + public static Criterion matchPbbIsid(int pbbIsid) { | ||
590 | + return new PbbIsidCriterion(pbbIsid); | ||
591 | + } | ||
592 | + | ||
593 | + /** | ||
584 | * Creates an extension criterion for the specified extension selector. | 594 | * Creates an extension criterion for the specified extension selector. |
585 | * | 595 | * |
586 | * @param extensionSelector extension selector | 596 | * @param extensionSelector extension selector | ... | ... |
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 java.util.Objects; | ||
19 | + | ||
20 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
21 | + | ||
22 | +/** | ||
23 | + * Implementation of PBB I-SID criterion (24 bits unsigned integer). | ||
24 | + */ | ||
25 | +public final class PbbIsidCriterion implements Criterion { | ||
26 | + private static final int MASK = 0xfffff; | ||
27 | + private final int pbbIsid; // PBB I-SID: 24 bits | ||
28 | + | ||
29 | + /** | ||
30 | + * Constructor. | ||
31 | + * | ||
32 | + * @param pbbIsid the PBB I-SID to match (24 bits) | ||
33 | + */ | ||
34 | + PbbIsidCriterion(int pbbIsid) { | ||
35 | + this.pbbIsid = pbbIsid & MASK; | ||
36 | + } | ||
37 | + | ||
38 | + @Override | ||
39 | + public Criterion.Type type() { | ||
40 | + return Criterion.Type.PBB_ISID; | ||
41 | + } | ||
42 | + | ||
43 | + /** | ||
44 | + * Gets the PBB I-SID to match. | ||
45 | + * | ||
46 | + * @return the PBB I-SID to match (24 bits) | ||
47 | + */ | ||
48 | + public int pbbIsid() { | ||
49 | + return this.pbbIsid; | ||
50 | + } | ||
51 | + | ||
52 | + @Override | ||
53 | + public String toString() { | ||
54 | + return toStringHelper(type().toString()) | ||
55 | + .add("pbbIsid", Long.toHexString(pbbIsid)).toString(); | ||
56 | + } | ||
57 | + | ||
58 | + @Override | ||
59 | + public int hashCode() { | ||
60 | + return Objects.hash(type().ordinal(), pbbIsid); | ||
61 | + } | ||
62 | + | ||
63 | + @Override | ||
64 | + public boolean equals(Object obj) { | ||
65 | + if (this == obj) { | ||
66 | + return true; | ||
67 | + } | ||
68 | + if (obj instanceof PbbIsidCriterion) { | ||
69 | + PbbIsidCriterion that = (PbbIsidCriterion) obj; | ||
70 | + return Objects.equals(pbbIsid, that.pbbIsid) && | ||
71 | + Objects.equals(this.type(), that.type()); | ||
72 | + } | ||
73 | + return false; | ||
74 | + } | ||
75 | +} |
... | @@ -279,6 +279,12 @@ public class CriteriaTest { | ... | @@ -279,6 +279,12 @@ public class CriteriaTest { |
279 | Criterion sameAsMatchOduSignalType1 = Criteria.matchOduSignalType(oduSigType1); | 279 | Criterion sameAsMatchOduSignalType1 = Criteria.matchOduSignalType(oduSigType1); |
280 | Criterion matchOduSignalType2 = Criteria.matchOduSignalType(oduSigType2); | 280 | Criterion matchOduSignalType2 = Criteria.matchOduSignalType(oduSigType2); |
281 | 281 | ||
282 | + int pbbIsid1 = 1; | ||
283 | + int pbbIsid2 = 2; | ||
284 | + Criterion matchPbbIsid1 = Criteria.matchPbbIsid(pbbIsid1); | ||
285 | + Criterion sameAsMatchPbbIsid1 = Criteria.matchPbbIsid(pbbIsid1); | ||
286 | + Criterion matchPbbIsid2 = Criteria.matchPbbIsid(pbbIsid2); | ||
287 | + | ||
282 | /** | 288 | /** |
283 | * Checks that a Criterion object has the proper type, and then converts | 289 | * Checks that a Criterion object has the proper type, and then converts |
284 | * it to the proper type. | 290 | * it to the proper type. |
... | @@ -337,6 +343,7 @@ public class CriteriaTest { | ... | @@ -337,6 +343,7 @@ public class CriteriaTest { |
337 | assertThatClassIsImmutable(LambdaCriterion.class); | 343 | assertThatClassIsImmutable(LambdaCriterion.class); |
338 | assertThatClassIsImmutable(OduSignalIdCriterion.class); | 344 | assertThatClassIsImmutable(OduSignalIdCriterion.class); |
339 | assertThatClassIsImmutable(OduSignalTypeCriterion.class); | 345 | assertThatClassIsImmutable(OduSignalTypeCriterion.class); |
346 | + assertThatClassIsImmutable(PbbIsidCriterion.class); | ||
340 | } | 347 | } |
341 | 348 | ||
342 | // PortCriterion class | 349 | // PortCriterion class |
... | @@ -1218,4 +1225,30 @@ public class CriteriaTest { | ... | @@ -1218,4 +1225,30 @@ public class CriteriaTest { |
1218 | .addEqualityGroup(matchOduSignalType2) | 1225 | .addEqualityGroup(matchOduSignalType2) |
1219 | .testEquals(); | 1226 | .testEquals(); |
1220 | } | 1227 | } |
1228 | + | ||
1229 | + // PbbIsidCriterion class | ||
1230 | + | ||
1231 | + /** | ||
1232 | + * Test the matchPbbIsid method. | ||
1233 | + */ | ||
1234 | + @Test | ||
1235 | + public void testMatchPbbIsidMethod() { | ||
1236 | + Criterion matchPbbIsid = Criteria.matchPbbIsid(pbbIsid1); | ||
1237 | + PbbIsidCriterion pbbIsidCriterion = | ||
1238 | + checkAndConvert(matchPbbIsid, | ||
1239 | + Criterion.Type.PBB_ISID, | ||
1240 | + PbbIsidCriterion.class); | ||
1241 | + assertThat(pbbIsidCriterion.pbbIsid(), is(equalTo(pbbIsid1))); | ||
1242 | + } | ||
1243 | + | ||
1244 | + /** | ||
1245 | + * Test the equals() method of the PbbIsidCriterion class. | ||
1246 | + */ | ||
1247 | + @Test | ||
1248 | + public void testPbbIsidCriterionEquals() { | ||
1249 | + new EqualsTester() | ||
1250 | + .addEqualityGroup(matchPbbIsid1, sameAsMatchPbbIsid1) | ||
1251 | + .addEqualityGroup(matchPbbIsid2) | ||
1252 | + .testEquals(); | ||
1253 | + } | ||
1221 | } | 1254 | } | ... | ... |
... | @@ -498,6 +498,7 @@ public abstract class FlowModBuilder { | ... | @@ -498,6 +498,7 @@ public abstract class FlowModBuilder { |
498 | break; | 498 | break; |
499 | case MPLS_TC: | 499 | case MPLS_TC: |
500 | case PBB_ISID: | 500 | case PBB_ISID: |
501 | + // TODO: need to implement PBB-ISID case when OpenFlowJ is ready | ||
501 | default: | 502 | default: |
502 | log.warn("Match type {} not yet implemented.", c.type()); | 503 | log.warn("Match type {} not yet implemented.", c.type()); |
503 | } | 504 | } | ... | ... |
-
Please register or login to post a comment