コード例 #1
0
ファイル: TestCondition.java プロジェクト: Ahmed-Azri/midonet
 @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));
 }
コード例 #2
0
  @Test
  public void ArpCacheTest()
      throws InterruptedException, KeeperException, StateAccessException, SerializationException {
    Setup.ensureZkDirectoryStructureExists(zkDir(), zkRoot);
    UUID routerId = getRouterZkManager().create();
    TestRouterBuilder routerBuilder = new TestRouterBuilder();
    client.getRouter(routerId, routerBuilder);

    pollCallCounts(routerBuilder, 1);
    assertThat("Build is called", routerBuilder.getBuildCallsCount(), equalTo(1));

    IPv4Addr ipAddr = IPv4Addr.fromString("192.168.0.0");
    ArpCacheEntry arpEntry = new ArpCacheEntry(MAC.random(), 0, 0, 0);
    // add an entry in the arp cache.
    routerBuilder.addNewArpEntry(ipAddr, arpEntry);

    pollCallCounts(routerBuilder, 1);
    assertEquals(arpEntry, routerBuilder.getArpEntryForIp(ipAddr));
    assertThat("Router update was notified", routerBuilder.getBuildCallsCount(), equalTo(1));
  }
コード例 #3
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));
 }
コード例 #4
0
ファイル: MockOvsdbClient.java プロジェクト: berendt/midonet
 public MockOvsdbClient(
     DatabaseSchema vtepSchema, MonitorRegistration monitorRegistrar, TransactionEngine engine)
     throws UnknownHostException {
   this(vtepSchema, monitorRegistrar, engine, IPv4Addr.fromString(DEFAULT_IP), DEFAULT_PORT);
 }