コード例 #1
0
ファイル: TestCondition.java プロジェクト: Ahmed-Azri/midonet
 @Test
 public void testNwDst() {
   Condition cond = new Condition();
   // Empty condition matches the packet.
   pktCtx.inPortId_$eq(UUID.randomUUID());
   Assert.assertTrue(cond.matches(pktCtx));
   // Inverting is ignored if the field is null.
   cond.nwDstInv = true;
   // Condition still matches the packet.
   Assert.assertTrue(cond.matches(pktCtx));
   cond.nwDstInv = false;
   // Set the nwDstIp to something different than the packet's 0x0a000b22.
   cond.nwDstIp = new IPv4Subnet(IPv4Addr.fromString("10.0.11.35"), 0);
   // Since nwDstLength is 0, the condition still matches the packet.
   Assert.assertTrue(cond.matches(pktCtx));
   // Now try inverting the result
   cond.nwDstInv = true;
   Assert.assertFalse(cond.matches(pktCtx));
   cond.nwDstInv = false;
   cond.nwDstIp = new IPv4Subnet(IPv4Addr.fromString("10.0.11.35"), 32);
   Assert.assertFalse(cond.matches(pktCtx));
   // Now try shorter prefixes:
   cond.nwDstIp = new IPv4Subnet(IPv4Addr.fromString("10.0.11.35"), 31);
   Assert.assertTrue(cond.matches(pktCtx));
   cond.nwDstIp = new IPv4Subnet(IPv4Addr.fromString("10.0.11.35"), 24);
   Assert.assertTrue(cond.matches(pktCtx));
   cond.nwDstIp = new IPv4Subnet(IPv4Addr.fromString("10.0.11.35"), 16);
   Assert.assertTrue(cond.matches(pktCtx));
   // Now try inverting
   cond.nwDstInv = true;
   Assert.assertFalse(cond.matches(pktCtx));
   cond.nwDstIp = new IPv4Subnet(IPv4Addr.fromString("10.0.11.35"), 32);
   Assert.assertTrue(cond.matches(pktCtx));
   // Remove the invert, set the nwDstIp to the packet's
   cond.nwDstInv = false;
   cond.nwDstIp = new IPv4Subnet(IPv4Addr.fromString("10.0.11.34"), 32);
   Assert.assertTrue(cond.matches(pktCtx));
   cond.nwDstInv = true;
   Assert.assertFalse(cond.matches(pktCtx));
 }