[ONOS-3494] Add test case for TCPFlags Criterion

Change-Id: I2575e52dc316039e528ff6216cec7c1d3195fe81
diff --git a/core/api/src/main/java/org/onosproject/net/flow/criteria/Criterion.java b/core/api/src/main/java/org/onosproject/net/flow/criteria/Criterion.java
index 10cb629..2666524 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/criteria/Criterion.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/criteria/Criterion.java
@@ -28,92 +28,136 @@
     enum Type {
         /** Switch input port. */
         IN_PORT,
+
         /** Switch physical input port. */
         IN_PHY_PORT,
+
         /** Metadata passed between tables. */
         METADATA,
+
         /** Ethernet destination address. */
         ETH_DST,
+
         /** Ethernet source address. */
         ETH_SRC,
+
         /** Ethernet frame type. */
         ETH_TYPE,
+
         /** VLAN id. */
         VLAN_VID,
+
         /** VLAN priority. */
         VLAN_PCP,
+
         /** IP DSCP (6 bits in ToS field). */
         IP_DSCP,
+
         /** IP ECN (2 bits in ToS field). */
         IP_ECN,
+
         /** IP protocol. */
         IP_PROTO,
+
         /** IPv4 source address. */
         IPV4_SRC,
+
         /** IPv4 destination address. */
         IPV4_DST,
+
         /** TCP source port. */
         TCP_SRC,
+
         /** TCP destination port. */
         TCP_DST,
+
         /** UDP source port. */
         UDP_SRC,
+
         /** UDP destination port. */
         UDP_DST,
+
         /** SCTP source port. */
         SCTP_SRC,
+
         /** SCTP destination port. */
         SCTP_DST,
+
         /** ICMP type. */
         ICMPV4_TYPE,
+
         /** ICMP code. */
         ICMPV4_CODE,
+
         /** ARP opcode. */
         ARP_OP,
+
         /** ARP source IPv4 address. */
         ARP_SPA,
+
         /** ARP target IPv4 address. */
         ARP_TPA,
+
         /** ARP source hardware address. */
         ARP_SHA,
+
         /** ARP target hardware address. */
         ARP_THA,
+
         /** IPv6 source address. */
         IPV6_SRC,
+
         /** IPv6 destination address. */
         IPV6_DST,
+
         /** IPv6 Flow Label. */
         IPV6_FLABEL,
+
         /** ICMPv6 type. */
         ICMPV6_TYPE,
+
         /** ICMPv6 code. */
         ICMPV6_CODE,
+
         /** Target address for ND. */
         IPV6_ND_TARGET,
+
         /** Source link-layer for ND. */
         IPV6_ND_SLL,
+
         /** Target link-layer for ND. */
         IPV6_ND_TLL,
+
         /** MPLS label. */
         MPLS_LABEL,
+
         /** MPLS TC. */
         MPLS_TC,
-        /** MPLS BoS bit. */
+
+        /**  MPLS BoS bit. */
         MPLS_BOS,
+
         /** PBB I-SID. */
         PBB_ISID,
+
         /** Logical Port Metadata. */
         TUNNEL_ID,
+
         /** IPv6 Extension Header pseudo-field. */
         IPV6_EXTHDR,
+
         /** Unassigned value: 40. */
         UNASSIGNED_40,
+
         /** PBB UCA header field. */
         PBB_UCA,
+
         /** TCP flags. */
         TCP_FLAGS,
+
         /** Output port from action set metadata. */
         ACTSET_OUTPUT,
+
         /** Packet type value. */
         PACKET_TYPE,
 
@@ -123,16 +167,17 @@
         //
         /** Optical channel signal ID (lambda). */
         OCH_SIGID,
+
         /** Optical channel signal type (fixed or flexible). */
         OCH_SIGTYPE,
+
         /** ODU (Optical channel Data Unit) signal ID. */
         ODU_SIGID,
+
         /** ODU (Optical channel Data Unit) signal type. */
         ODU_SIGTYPE,
 
-        /**
-         * An empty criterion.
-         */
+        /** An empty criterion. */
         DUMMY
     }
 
@@ -182,4 +227,41 @@
             return this.value;
         }
     }
+
+    enum TCPFlags {
+
+        /** ECN-nonce concealment protection. */
+        NS((short) (1 << 0)),
+        /** Congestion Window Reduced. */
+        CWR((short) (1 << 1)),
+        /** ECN-Echo. **/
+        ECE((short) (1 << 2)),
+        /** Urgent pointer field is significant. */
+        URG((short) (1 << 3)),
+        /** Acknowledgment field is significant. */
+        ACK((short) (1 << 4)),
+        /** Push the buffered data to the receiving application. */
+        PSH((short) (1 << 5)),
+        /** Reset the connection. */
+        RST((short) (1 << 6)),
+        /** Synchronize sequence numbers. */
+        SYN((short) (1 << 7)),
+        /** No more data from sender. */
+        FIN((short) (1 << 8));
+
+        private short value;
+
+        TCPFlags(short value) {
+            this.value = value;
+        }
+
+        /**
+         * Gets the value as an integer.
+         *
+         * @return the value as an integer
+         */
+        public short getValue() {
+            return this.value;
+        }
+    }
 }
diff --git a/core/api/src/test/java/org/onosproject/net/flow/criteria/CriteriaTest.java b/core/api/src/test/java/org/onosproject/net/flow/criteria/CriteriaTest.java
index d86744d..56a6ff6 100644
--- a/core/api/src/test/java/org/onosproject/net/flow/criteria/CriteriaTest.java
+++ b/core/api/src/test/java/org/onosproject/net/flow/criteria/CriteriaTest.java
@@ -42,6 +42,7 @@
 import org.onosproject.net.PortNumber;
 
 import com.google.common.testing.EqualsTester;
+
 /**
  * Unit tests for the Criteria class and its subclasses.
  */
@@ -135,6 +136,24 @@
     Criterion sameAsMatchUdpPort1 = Criteria.matchUdpSrc(tpPort1);
     Criterion matchUdpPort2 = Criteria.matchUdpDst(tpPort2);
 
+
+    int tcpFlags1 =
+        Criterion.TCPFlags.NS.getValue() |
+        Criterion.TCPFlags.CWR.getValue() |
+        Criterion.TCPFlags.ECE.getValue() |
+        Criterion.TCPFlags.URG.getValue() |
+        Criterion.TCPFlags.ACK.getValue() |
+        Criterion.TCPFlags.PSH.getValue() |
+        Criterion.TCPFlags.RST.getValue() |
+        Criterion.TCPFlags.SYN.getValue();
+
+    int tcpFlags2 = tcpFlags1 |
+        Criterion.TCPFlags.FIN.getValue();
+
+    Criterion matchTcpFlags1 = Criteria.matchTcpFlags(tcpFlags1);
+    Criterion sameAsmatchTcpFlags1 = Criteria.matchTcpFlags(tcpFlags1);
+    Criterion matchTcpFlags2 = Criteria.matchTcpFlags(tcpFlags2);
+
     Criterion matchSctpPort1 = Criteria.matchSctpSrc(tpPort1);
     Criterion sameAsMatchSctpPort1 = Criteria.matchSctpSrc(tpPort1);
     Criterion matchSctpPort2 = Criteria.matchSctpDst(tpPort2);
@@ -174,28 +193,28 @@
     private Ip6Address ip6TargetAddress1 = Ip6Address.valueOf(IPV6_ADDR1);
     private Ip6Address ip6TargetAddress2 = Ip6Address.valueOf(IPV6_ADDR2);
     Criterion matchIpv6TargetAddr1 =
-        Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
+            Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
     Criterion sameAsMatchIpv6TargetAddr1 =
-        Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
+            Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
     Criterion matchIpv6TargetAddr2 =
-        Criteria.matchIPv6NDTargetAddress(ip6TargetAddress2);
+            Criteria.matchIPv6NDTargetAddress(ip6TargetAddress2);
 
     private static final String LL_MAC1 = "00:00:00:00:00:01";
     private static final String LL_MAC2 = "00:00:00:00:00:02";
     private MacAddress llMac1 = MacAddress.valueOf(LL_MAC1);
     private MacAddress llMac2 = MacAddress.valueOf(LL_MAC2);
     Criterion matchSrcLlAddr1 =
-        Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
+            Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
     Criterion sameAsMatchSrcLlAddr1 =
-        Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
+            Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
     Criterion matchSrcLlAddr2 =
-        Criteria.matchIPv6NDSourceLinkLayerAddress(llMac2);
+            Criteria.matchIPv6NDSourceLinkLayerAddress(llMac2);
     Criterion matchTargetLlAddr1 =
-        Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
+            Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
     Criterion sameAsMatchTargetLlAddr1 =
-        Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
+            Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
     Criterion matchTargetLlAddr2 =
-        Criteria.matchIPv6NDTargetLinkLayerAddress(llMac2);
+            Criteria.matchIPv6NDTargetLinkLayerAddress(llMac2);
 
     MplsLabel mpls1 = MplsLabel.mplsLabel(1);
     MplsLabel mpls2 = MplsLabel.mplsLabel(2);
@@ -219,13 +238,13 @@
         Criterion.IPv6ExthdrFlags.HOP.getValue() |
         Criterion.IPv6ExthdrFlags.UNREP.getValue();
     int ipv6ExthdrFlags2 = ipv6ExthdrFlags1 |
-        Criterion.IPv6ExthdrFlags.UNSEQ.getValue();
+            Criterion.IPv6ExthdrFlags.UNSEQ.getValue();
     Criterion matchIpv6ExthdrFlags1 =
-        Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1);
+            Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1);
     Criterion sameAsMatchIpv6ExthdrFlags1 =
-        Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1);
+            Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1);
     Criterion matchIpv6ExthdrFlags2 =
-        Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags2);
+            Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags2);
 
     Criterion matchOchSignalType1 = Criteria.matchOchSignalType(OchSignalType.FIXED_GRID);
     Criterion sameAsMatchOchSignalType1 = Criteria.matchOchSignalType(OchSignalType.FIXED_GRID);
@@ -242,8 +261,8 @@
     Criterion matchOchSignal2 =
             Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 4, 8));
 
-    final OduSignalId odu1 = oduSignalId(1, 80, new byte [] {1, 1, 2, 2, 1, 2, 2, 1, 2, 2});
-    final OduSignalId odu2 = oduSignalId(3, 8, new byte [] {1, 0, 0, 0, 0, 0, 0, 0, 0, 0});
+    final OduSignalId odu1 = oduSignalId(1, 80, new byte[]{1, 1, 2, 2, 1, 2, 2, 1, 2, 2});
+    final OduSignalId odu2 = oduSignalId(3, 8, new byte[]{1, 0, 0, 0, 0, 0, 0, 0, 0, 0});
     Criterion matchOduSignalId1 = Criteria.matchOduSignalId(odu1);
     Criterion sameAsMatchOduSignalId1 = Criteria.matchOduSignalId(odu1);
     Criterion matchOduSignalId2 = Criteria.matchOduSignalId(odu2);
@@ -259,9 +278,9 @@
      * it to the proper type.
      *
      * @param criterion Criterion object to convert
-     * @param type Enumerated type value for the Criterion class
-     * @param clazz Desired Criterion class
-     * @param <T> The type the caller wants returned
+     * @param type      Enumerated type value for the Criterion class
+     * @param clazz     Desired Criterion class
+     * @param <T>       The type the caller wants returned
      * @return converted object
      */
     @SuppressWarnings("unchecked")
@@ -297,6 +316,7 @@
         assertThatClassIsImmutable(IPCriterion.class);
         assertThatClassIsImmutable(TcpPortCriterion.class);
         assertThatClassIsImmutable(UdpPortCriterion.class);
+        assertThatClassIsImmutable(TcpFlagsCriterion.class);
         assertThatClassIsImmutable(SctpPortCriterion.class);
         assertThatClassIsImmutable(IcmpTypeCriterion.class);
         assertThatClassIsImmutable(IcmpCodeCriterion.class);
@@ -395,8 +415,8 @@
         Criterion matchEthDst = Criteria.matchEthDst(mac1);
         EthCriterion ethCriterion =
                 checkAndConvert(matchEthDst,
-                        Criterion.Type.ETH_DST,
-                        EthCriterion.class);
+                                Criterion.Type.ETH_DST,
+                                EthCriterion.class);
         assertThat(ethCriterion.mac(), is(equalTo(mac1)));
     }
 
@@ -461,8 +481,8 @@
         Criterion matchVlanId = Criteria.matchVlanId(vlanId1);
         VlanIdCriterion vlanIdCriterion =
                 checkAndConvert(matchVlanId,
-                        Criterion.Type.VLAN_VID,
-                        VlanIdCriterion.class);
+                                Criterion.Type.VLAN_VID,
+                                VlanIdCriterion.class);
         assertThat(vlanIdCriterion.vlanId(), is(equalTo(vlanId1)));
     }
 
@@ -487,8 +507,8 @@
         Criterion matchVlanPcp = Criteria.matchVlanPcp(vlanPcp1);
         VlanPcpCriterion vlanPcpCriterion =
                 checkAndConvert(matchVlanPcp,
-                        Criterion.Type.VLAN_PCP,
-                        VlanPcpCriterion.class);
+                                Criterion.Type.VLAN_PCP,
+                                VlanPcpCriterion.class);
         assertThat(vlanPcpCriterion.priority(), is(equalTo(vlanPcp1)));
     }
 
@@ -513,8 +533,8 @@
         Criterion matchIPDscp = Criteria.matchIPDscp(ipDscp1);
         IPDscpCriterion ipDscpCriterion =
                 checkAndConvert(matchIPDscp,
-                        Criterion.Type.IP_DSCP,
-                        IPDscpCriterion.class);
+                                Criterion.Type.IP_DSCP,
+                                IPDscpCriterion.class);
         assertThat(ipDscpCriterion.ipDscp(), is(equalTo(ipDscp1)));
     }
 
@@ -539,8 +559,8 @@
         Criterion matchIPEcn = Criteria.matchIPEcn(ipEcn1);
         IPEcnCriterion ipEcnCriterion =
                 checkAndConvert(matchIPEcn,
-                        Criterion.Type.IP_ECN,
-                        IPEcnCriterion.class);
+                                Criterion.Type.IP_ECN,
+                                IPEcnCriterion.class);
         assertThat(ipEcnCriterion.ipEcn(), is(equalTo(ipEcn1)));
     }
 
@@ -565,8 +585,8 @@
         Criterion matchIPProtocol = Criteria.matchIPProtocol(protocol1);
         IPProtocolCriterion ipProtocolCriterion =
                 checkAndConvert(matchIPProtocol,
-                        Criterion.Type.IP_PROTO,
-                        IPProtocolCriterion.class);
+                                Criterion.Type.IP_PROTO,
+                                IPProtocolCriterion.class);
         assertThat(ipProtocolCriterion.protocol(), is(equalTo(protocol1)));
     }
 
@@ -604,8 +624,8 @@
         Criterion matchIPDst = Criteria.matchIPDst(ip1);
         IPCriterion ipCriterion =
                 checkAndConvert(matchIPDst,
-                        Criterion.Type.IPV4_DST,
-                        IPCriterion.class);
+                                Criterion.Type.IPV4_DST,
+                                IPCriterion.class);
         assertThat(ipCriterion.ip(), is(equalTo(ip1)));
     }
 
@@ -617,8 +637,8 @@
         Criterion matchIpv6Src = Criteria.matchIPv6Src(ipv61);
         IPCriterion ipCriterion =
                 checkAndConvert(matchIpv6Src,
-                        Criterion.Type.IPV6_SRC,
-                        IPCriterion.class);
+                                Criterion.Type.IPV6_SRC,
+                                IPCriterion.class);
         assertThat(ipCriterion.ip(), is(ipv61));
     }
 
@@ -630,8 +650,8 @@
         Criterion matchIPv6Dst = Criteria.matchIPv6Dst(ipv61);
         IPCriterion ipCriterion =
                 checkAndConvert(matchIPv6Dst,
-                        Criterion.Type.IPV6_DST,
-                        IPCriterion.class);
+                                Criterion.Type.IPV6_DST,
+                                IPCriterion.class);
         assertThat(ipCriterion.ip(), is(equalTo(ipv61)));
     }
 
@@ -674,8 +694,8 @@
         Criterion matchTcpDst = Criteria.matchTcpDst(tpPort1);
         TcpPortCriterion tcpPortCriterion =
                 checkAndConvert(matchTcpDst,
-                        Criterion.Type.TCP_DST,
-                        TcpPortCriterion.class);
+                                Criterion.Type.TCP_DST,
+                                TcpPortCriterion.class);
         assertThat(tcpPortCriterion.tcpPort(), is(equalTo(tpPort1)));
     }
 
@@ -713,8 +733,8 @@
         Criterion matchUdpDst = Criteria.matchUdpDst(tpPort1);
         UdpPortCriterion udpPortCriterion =
                 checkAndConvert(matchUdpDst,
-                        Criterion.Type.UDP_DST,
-                        UdpPortCriterion.class);
+                                Criterion.Type.UDP_DST,
+                                UdpPortCriterion.class);
         assertThat(udpPortCriterion.udpPort(), is(equalTo(tpPort1)));
     }
 
@@ -729,6 +749,19 @@
                 .testEquals();
     }
 
+    // TcpFlagsCriterion class
+
+    /**
+     * Test the equals() method of the TcpFlagsCriterion class.
+     */
+    @Test
+    public void testTcpFlagsCriterionEquals() {
+        new EqualsTester()
+                .addEqualityGroup(matchTcpFlags1, sameAsmatchTcpFlags1)
+                .addEqualityGroup(matchTcpFlags2)
+                .testEquals();
+    }
+
     // SctpPortCriterion class
 
     /**
@@ -752,8 +785,8 @@
         Criterion matchSctpDst = Criteria.matchSctpDst(tpPort1);
         SctpPortCriterion sctpPortCriterion =
                 checkAndConvert(matchSctpDst,
-                        Criterion.Type.SCTP_DST,
-                        SctpPortCriterion.class);
+                                Criterion.Type.SCTP_DST,
+                                SctpPortCriterion.class);
         assertThat(sctpPortCriterion.sctpPort(), is(equalTo(tpPort1)));
     }
 
@@ -911,7 +944,7 @@
     @Test
     public void testMatchIPv6NDTargetAddressMethod() {
         Criterion matchTargetAddress =
-            Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
+                Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
         IPv6NDTargetAddressCriterion targetAddressCriterion =
                 checkAndConvert(matchTargetAddress,
                                 Criterion.Type.IPV6_ND_TARGET,
@@ -940,11 +973,11 @@
     @Test
     public void testMatchIPv6NDSourceLinkLayerAddressMethod() {
         Criterion matchSrcLlAddr =
-            Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
+                Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
         IPv6NDLinkLayerAddressCriterion srcLlCriterion =
                 checkAndConvert(matchSrcLlAddr,
-                        Criterion.Type.IPV6_ND_SLL,
-                        IPv6NDLinkLayerAddressCriterion.class);
+                                Criterion.Type.IPV6_ND_SLL,
+                                IPv6NDLinkLayerAddressCriterion.class);
         assertThat(srcLlCriterion.mac(), is(equalTo(llMac1)));
     }
 
@@ -954,11 +987,11 @@
     @Test
     public void testMatchIPv6NDTargetLinkLayerAddressMethod() {
         Criterion matchTargetLlAddr =
-            Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
+                Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
         IPv6NDLinkLayerAddressCriterion targetLlCriterion =
                 checkAndConvert(matchTargetLlAddr,
-                        Criterion.Type.IPV6_ND_TLL,
-                        IPv6NDLinkLayerAddressCriterion.class);
+                                Criterion.Type.IPV6_ND_TLL,
+                                IPv6NDLinkLayerAddressCriterion.class);
         assertThat(targetLlCriterion.mac(), is(equalTo(llMac1)));
     }
 
@@ -988,8 +1021,8 @@
         Criterion matchMplsLabel = Criteria.matchMplsLabel(mpls1);
         MplsCriterion mplsCriterion =
                 checkAndConvert(matchMplsLabel,
-                        Criterion.Type.MPLS_LABEL,
-                        MplsCriterion.class);
+                                Criterion.Type.MPLS_LABEL,
+                                MplsCriterion.class);
         assertThat(mplsCriterion.label(), is(equalTo(mpls1)));
     }
 
@@ -1025,10 +1058,10 @@
      */
     @Test
     public void testTunnelIdCriterionEquals() {
-       new EqualsTester()
-               .addEqualityGroup(matchTunnelId1, sameAsMatchTunnelId1)
-               .addEqualityGroup(matchTunnelId2)
-               .testEquals();
+        new EqualsTester()
+                .addEqualityGroup(matchTunnelId1, sameAsMatchTunnelId1)
+                .addEqualityGroup(matchTunnelId2)
+                .testEquals();
     }
 
     // IPv6ExthdrFlagsCriterion class
@@ -1039,11 +1072,11 @@
     @Test
     public void testMatchIPv6ExthdrFlagsMethod() {
         Criterion matchExthdrFlags =
-            Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1);
+                Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1);
         IPv6ExthdrFlagsCriterion exthdrFlagsCriterion =
                 checkAndConvert(matchExthdrFlags,
-                        Criterion.Type.IPV6_EXTHDR,
-                        IPv6ExthdrFlagsCriterion.class);
+                                Criterion.Type.IPV6_EXTHDR,
+                                IPv6ExthdrFlagsCriterion.class);
         assertThat(exthdrFlagsCriterion.exthdrFlags(),
                    is(equalTo(ipv6ExthdrFlags1)));
     }