@Test public void testIpAddrGroup() { // Should match with empty condition. Condition cond = new Condition(); Assert.assertTrue(cond.matches(pktCtx)); // Should fail to match with empty IPAddrGroup for source or dest. IPAddrGroup ipAddrGroupEmpty = IPAddrGroup.fromAddrs(UUID.randomUUID(), new IPAddr[] {}); cond.ipAddrGroupDst = ipAddrGroupEmpty; Assert.assertFalse(cond.matches(pktCtx)); cond = new Condition(); cond.ipAddrGroupSrc = ipAddrGroupEmpty; Assert.assertFalse(cond.matches(pktCtx)); // Should match with inverted empty IPAddrGroup for source or dest. cond = new Condition(); cond.ipAddrGroupDst = ipAddrGroupEmpty; cond.invIpAddrGroupIdDst = true; Assert.assertTrue(cond.matches(pktCtx)); cond = new Condition(); cond.ipAddrGroupSrc = ipAddrGroupEmpty; cond.invIpAddrGroupIdSrc = true; Assert.assertTrue(cond.matches(pktCtx)); // Should match with dest set containing dest address. IPAddrGroup ipAddrGroupDst = IPAddrGroup.fromAddrs( UUID.randomUUID(), new IPAddr[] {dstIpAddr, new IPv4Addr(0x12345678)}); cond = new Condition(); cond.ipAddrGroupDst = ipAddrGroupDst; Assert.assertTrue(cond.matches(pktCtx)); // And not when inverted. cond.invIpAddrGroupIdDst = true; Assert.assertFalse(cond.matches(pktCtx)); // Should not match when source set contains dest, not source, address. cond = new Condition(); cond.ipAddrGroupSrc = ipAddrGroupDst; Assert.assertFalse(cond.matches(pktCtx)); cond.invIpAddrGroupIdSrc = true; Assert.assertTrue(cond.matches(pktCtx)); // The above with source and dest inverted. IPAddrGroup ipAddrGroupSrc = IPAddrGroup.fromAddrs( UUID.randomUUID(), new IPAddr[] {srcIpAddr, new IPv4Addr(0x87654321)}); cond = new Condition(); cond.ipAddrGroupSrc = ipAddrGroupSrc; Assert.assertTrue(cond.matches(pktCtx)); cond.invIpAddrGroupIdSrc = true; Assert.assertFalse(cond.matches(pktCtx)); cond = new Condition(); cond.ipAddrGroupDst = ipAddrGroupSrc; Assert.assertFalse(cond.matches(pktCtx)); cond.invIpAddrGroupIdDst = true; Assert.assertTrue(cond.matches(pktCtx)); // Should not match when source matches and dest doesn't, or vice-versa. cond = new Condition(); cond.ipAddrGroupDst = ipAddrGroupDst; cond.ipAddrGroupSrc = ipAddrGroupDst; Assert.assertFalse(cond.matches(pktCtx)); cond.invIpAddrGroupIdSrc = true; Assert.assertTrue(cond.matches(pktCtx)); cond = new Condition(); cond.ipAddrGroupDst = ipAddrGroupSrc; cond.ipAddrGroupSrc = ipAddrGroupSrc; Assert.assertFalse(cond.matches(pktCtx)); cond.invIpAddrGroupIdDst = true; Assert.assertTrue(cond.matches(pktCtx)); // Should match when both match. cond = new Condition(); cond.ipAddrGroupDst = ipAddrGroupDst; cond.ipAddrGroupSrc = ipAddrGroupSrc; }