Jian Li
Committed by Gerrit Code Review

[onos-3494] Implement TCP Flags Criterion to Southbound

Change-Id: I65bdfa7286249dabfc8109faca140a000efd5e48
...@@ -230,6 +230,16 @@ public final class Criteria { ...@@ -230,6 +230,16 @@ public final class Criteria {
230 } 230 }
231 231
232 /** 232 /**
233 + * Creates a match on TCP flags using the specified value.
234 + *
235 + * @param flags TCP flags
236 + * @return match criterion
237 + */
238 + public static Criterion matchTcpFlags(int flags) {
239 + return new TcpFlagsCriterion(flags);
240 + }
241 +
242 + /**
233 * Creates a match on UDP source port field using the specified value. 243 * Creates a match on UDP source port field using the specified value.
234 * 244 *
235 * @param udpPort UDP source port 245 * @param udpPort UDP source port
......
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 TCP flags criterion (12 bits unsigned integer).
24 + */
25 +public final class TcpFlagsCriterion implements Criterion {
26 + private static final int MASK = 0xfffff;
27 + private final int flags; // TCP flags: 12 bits
28 +
29 + /**
30 + * Constructor.
31 + *
32 + * @param flags the TCP flags to match (12 bits)
33 + */
34 + TcpFlagsCriterion(int flags) {
35 + this.flags = flags & MASK;
36 + }
37 +
38 + @Override
39 + public Type type() {
40 + return Type.TCP_FLAGS;
41 + }
42 +
43 + /**
44 + * Gets the TCP flags to match.
45 + *
46 + * @return the TCP flags to match (12 bits)
47 + */
48 + public int flags() {
49 + return flags;
50 + }
51 +
52 + @Override
53 + public String toString() {
54 + return toStringHelper(type().toString())
55 + .add("flags", Long.toHexString(flags)).toString();
56 + }
57 +
58 + @Override
59 + public int hashCode() {
60 + return Objects.hash(type().ordinal(), flags);
61 + }
62 +
63 + @Override
64 + public boolean equals(Object obj) {
65 + if (this == obj) {
66 + return true;
67 + }
68 + if (obj instanceof TcpFlagsCriterion) {
69 + TcpFlagsCriterion that = (TcpFlagsCriterion) obj;
70 + return Objects.equals(flags, that.flags) &&
71 + Objects.equals(this.type(), that.type());
72 + }
73 + return false;
74 + }
75 +}