示例#1
0
 @Override
 public String toString() {
   return "Data{"
       + "nwAddr="
       + IPv4Addr.intToString(nwAddr)
       + ", nwLength="
       + nwLength
       + ", portAddr="
       + IPv4Addr.intToString(portAddr)
       + ", hwAddr="
       + hwAddr
       + ", bgps="
       + bgps
       + '}';
 }
示例#2
0
 public MockConnectionInfo(IPv4Addr addr, int port) throws UnknownHostException {
   super(null, ConnectionType.ACTIVE);
   this.remoteAddr = InetAddress.getByAddress(addr.toBytes());
   this.remotePort = port;
   this.localAddr = InetAddress.getLocalHost();
   this.localPort = new Random().nextInt(1000) + 51000;
 }
示例#3
0
 @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));
 }
示例#4
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));
  }
示例#5
0
 @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));
 }
示例#6
0
 public MockOvsdbClient(
     DatabaseSchema vtepSchema, MonitorRegistration monitorRegistrar, TransactionEngine engine)
     throws UnknownHostException {
   this(vtepSchema, monitorRegistrar, engine, IPv4Addr.fromString(DEFAULT_IP), DEFAULT_PORT);
 }
示例#7
0
 public RouterPort setPortAddr(String portAddr) {
   getData().portAddr = IPv4Addr.stringToInt(portAddr);
   return this;
 }
示例#8
0
 public String getPortAddr() {
   return IPv4Addr.intToString(getData().portAddr);
 }
示例#9
0
 public RouterPort setNwAddr(String nwAddr) {
   getData().nwAddr = IPv4Addr.stringToInt(nwAddr);
   return this;
 }
示例#10
0
 public String getNwAddr() {
   return IPv4Addr.intToString(getData().nwAddr);
 }