Jian Li
Committed by Gerrit Code Review

[ONOS-3480] Implement MPLS TC Criterion to Southbound

Change-Id: I6fab221785b07f1962d43a86dd0af664be40a537
...@@ -453,6 +453,16 @@ public final class Criteria { ...@@ -453,6 +453,16 @@ public final class Criteria {
453 } 453 }
454 454
455 /** 455 /**
456 + * Creates a match on MPLS TC.
457 + *
458 + * @param mplsTc MPLS TC (3 bits)
459 + * @return match criterion
460 + */
461 + public static Criterion matchMplsTc(byte mplsTc) {
462 + return new MplsTcCriterion(mplsTc);
463 + }
464 +
465 + /**
456 * Creates a match on Tunnel ID. 466 * Creates a match on Tunnel ID.
457 * 467 *
458 * @param tunnelId Tunnel ID (64 bits) 468 * @param tunnelId Tunnel ID (64 bits)
......
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 MPLS TC criterion (3 bits).
24 + */
25 +public final class MplsTcCriterion implements Criterion {
26 + private static final byte MASK = 0x7;
27 + private final byte mplsTc;
28 +
29 + /**
30 + * Constructor.
31 + *
32 + * @param mplsTc the MPLS TC to match (3 bits)
33 + */
34 + MplsTcCriterion(byte mplsTc) {
35 + this.mplsTc = (byte) (mplsTc & MASK);
36 + }
37 +
38 + @Override
39 + public Type type() {
40 + return Type.MPLS_TC;
41 + }
42 +
43 + /**
44 + * Gets the MPLS TC to match.
45 + *
46 + * @return the MPLS TC to match (3 bits)
47 + */
48 + public byte tc() {
49 + return mplsTc;
50 + }
51 +
52 + @Override
53 + public String toString() {
54 + return toStringHelper(type().toString())
55 + .add("tc", Long.toHexString(mplsTc)).toString();
56 + }
57 +
58 + @Override
59 + public int hashCode() {
60 + return Objects.hash(type().ordinal(), mplsTc);
61 + }
62 +
63 + @Override
64 + public boolean equals(Object obj) {
65 + if (this == obj) {
66 + return true;
67 + }
68 + if (obj instanceof MplsTcCriterion) {
69 + MplsTcCriterion that = (MplsTcCriterion) obj;
70 + return Objects.equals(mplsTc, that.mplsTc) &&
71 + Objects.equals(this.type(), that.type());
72 + }
73 + return false;
74 + }
75 +}