@Test public void testNwSrc() { Condition cond = new Condition(); pktCtx.inPortId_$eq(UUID.randomUUID()); Assert.assertTrue(cond.matches(pktCtx)); // Inverting nwSrc has no effect when it's wild-carded. cond.nwSrcInv = true; Assert.assertTrue(cond.matches(pktCtx)); cond.nwSrcInv = false; // Set the nwSrcIp to something different than the packet's 0x0a001406. cond.nwSrcIp = new IPv4Subnet(IPv4Addr.fromString("10.0.20.3"), 0); // Since nwSrcLength is still 0, the condition still matches the packet. Assert.assertTrue(cond.matches(pktCtx)); cond.nwSrcIp = new IPv4Subnet(IPv4Addr.fromString("10.0.20.3"), 32); Assert.assertFalse(cond.matches(pktCtx)); // Now try shorter prefixes: cond.nwSrcIp = new IPv4Subnet(IPv4Addr.fromString("10.0.20.3"), 24); Assert.assertTrue(cond.matches(pktCtx)); cond.nwSrcIp = new IPv4Subnet(IPv4Addr.fromString("10.0.20.3"), 16); Assert.assertTrue(cond.matches(pktCtx)); // Now try length 0 with an ip that differs in the left-most bit. cond.nwSrcIp = new IPv4Subnet(IPv4Addr.fromString("250.1.1.4"), 1); Assert.assertFalse(cond.matches(pktCtx)); cond.nwSrcIp = new IPv4Subnet(IPv4Addr.fromString("250.1.1.4"), 0); Assert.assertTrue(cond.matches(pktCtx)); cond.nwSrcInv = true; Assert.assertFalse(cond.matches(pktCtx)); // Now increase the maskLength. The packet doesn't match the // condition's srcIp, but the nwSrcInv is true. cond.nwSrcIp = new IPv4Subnet(IPv4Addr.fromString("250.1.1.4"), 32); Assert.assertTrue(cond.matches(pktCtx)); // Remove the invert, set the nwSrcIp to the packet's cond.nwSrcInv = false; Assert.assertFalse(cond.matches(pktCtx)); cond.nwSrcIp = new IPv4Subnet(IPv4Addr.fromString("10.0.20.6"), 32); Assert.assertTrue(cond.matches(pktCtx)); cond.nwSrcInv = true; Assert.assertFalse(cond.matches(pktCtx)); }