Package com.vmware.bdd.entity

Examples of com.vmware.bdd.entity.IpBlockEntity


                     gateway, dns1, dns2);
         networkDao.insert(network);
         List<IpBlockEntity> blocks =
               new ArrayList<IpBlockEntity>(ipBlocks.size());
         for (IpBlock ib : ipBlocks) {
            IpBlockEntity blk =
                  new IpBlockEntity(null, IpBlockEntity.FREE_BLOCK_OWNER_ID,
                        BlockType.FREE, IpAddressUtil.getAddressAsLong(ib
                              .getBeginIp()), IpAddressUtil.getAddressAsLong(ib
                              .getEndIp()));
            blocks.add(blk);
         }
View Full Code Here


      long netmask = IpAddressUtil.getAddressAsLong(network.getNetmask());
      IpAddressUtil.verifyIPBlocks(ipBlocks, netmask);
      List<IpBlockEntity> blocks =
            new ArrayList<IpBlockEntity>(ipBlocks.size());
      for (IpBlock ib : ipBlocks) {
         IpBlockEntity blk =
               new IpBlockEntity(network, IpBlockEntity.FREE_BLOCK_OWNER_ID,
                     BlockType.FREE, IpAddressUtil.getAddressAsLong(ib
                           .getBeginIp()), IpAddressUtil.getAddressAsLong(ib
                           .getEndIp()));
         blocks.add(blk);
      }
View Full Code Here

    */
   @Override
   @Transactional
   public synchronized void free(NetworkEntity network, long clusterId,
         long ipAddr) {
      IpBlockEntity block =
            new IpBlockEntity(network, clusterId, BlockType.ASSIGNED, ipAddr,
                  ipAddr);
      List<IpBlockEntity> ipBlocks = new ArrayList<IpBlockEntity>();
      ipBlocks.add(block);
      networkDao.free(network, clusterId, ipBlocks);
   }
View Full Code Here

         int maxValue = count * 10;
         Long end = 1 + (long) (Math.random() * maxValue) % maxValue;
         Long begin = (long) (Math.random() * end) % end;

         blocks.add(new IpBlockEntity(network, ownerId, blockType, begin, end));
      }
      return blocks;
   }
View Full Code Here

      if (block.getLength() > 1 && Math.random() < 0.5) {
         Long splitIp = block.getBeginIp() +
               (long) (Math.random() * (block.getLength() - 1))
               % (block.getLength() - 1);

         IpBlockEntity left = new IpBlockEntity(block.getNetwork(), block.getOwnerId(),
               block.getType(),
               block.getBeginIp(),
               splitIp);

         IpBlockEntity right = new IpBlockEntity(block.getNetwork(), block.getOwnerId(),
               block.getType(),
               splitIp + 1,
               block.getEndIp());

         split.add(left);
         split.add(right);
      } else {
         IpBlockEntity dup = new IpBlockEntity(block.getNetwork(), block.getOwnerId(),
               block.getType(), block.getBeginIp(), block.getEndIp());
         split.add(dup);
      }

      return split;
View Full Code Here

            netmask, gateway, dns1, dns2);
      networkDao.insert(network);
      Long ipBase = IpAddressUtil.getAddressAsLong(InetAddress.getByName("192.168.1.1"));
      List<IpBlockEntity> ipBlocks = new ArrayList<IpBlockEntity>();
      for (int i = 0; i < 10; i++) {
         ipBlocks.add(new IpBlockEntity(network, IpBlockEntity.FREE_BLOCK_OWNER_ID,
               BlockType.FREE, ipBase + i * 10, ipBase + i * 10 + 10));
      }

      networkDao.addIpBlocks(network, ipBlocks);
      logger.info(network);
View Full Code Here

      final Long endIp = IpAddressUtil
            .getAddressAsLong(InetAddress.getByName("0.2.0.0"));

      NetworkEntity network = new NetworkEntity(portGroup, portGroup, allocType,
            netmask, gateway, dns1, dns2);
      IpBlockEntity originalBlock = new IpBlockEntity(network,
            IpBlockEntity.FREE_BLOCK_OWNER_ID, BlockType.FREE, beginIp, endIp);
      networkDao.insert(network);

      List<IpBlockEntity> ipBlocks = new ArrayList<IpBlockEntity>();
      ipBlocks.add(originalBlock);

      networkDao.addIpBlocks(network, ipBlocks);
      logger.info(network);

      List<List<IpBlockEntity>> allocLists = new ArrayList<List<IpBlockEntity>>();
      List<Integer> allocSizes = new ArrayList<Integer>();
      List<Long> allocOwners = new ArrayList<Long>();
      long totalAssigned = 0L;

      Long maxOwnerId = 100L; // min is 0L
      int minAllocSize = 1;
      int maxAllocSize = 1000;

      final Long totalIps = endIp - beginIp + 1;

      long nextLogTimeMs = System.currentTimeMillis() + 1000;

      logger.info("strart random alloc/free stress test");
      /**
       * try to alloc until out of IPs
       */
      while (true) {
         long now = System.currentTimeMillis();
         if (nextLogTimeMs < now) {
            nextLogTimeMs = now + 1000;
            logger.info("allocated: " + totalAssigned + "/" + totalIps + " ("
                  + totalAssigned / (double) totalIps + ")");
         }

         if (Math.random() < 0.8) { // alloc
            final Long ownerId = (long) (Math.random() * maxOwnerId) % maxOwnerId;
            int rndCount = (int) (Math.random() * maxAllocSize) % maxAllocSize;
            final int count = Math.max(minAllocSize, rndCount);

            try {
               List<IpBlockEntity> allocated = networkDao.alloc(network, ownerId, count);
               allocLists.add(allocated);
               allocSizes.add(count);
               allocOwners.add(ownerId);
               totalAssigned += totalAssigned + count;
               logger.debug("alloc: "
                     + collectionToString(allocLists.get(allocLists.size() - 1)));
            } catch (NetworkException ex) {
               assertTrue("out of ip resource", network.getFree() < count);
               break;
            }
         } else { // free
            if (!allocLists.isEmpty()) {
               int idx = (int) (Math.random() * allocLists.size()) % allocLists.size();
               final List<IpBlockEntity> toBeFreed = allocLists.remove(idx);
               final Long ownerId = allocOwners.remove(idx);

               logger.debug("to free: " + collectionToString(toBeFreed));
               networkDao.free(network, ownerId, toBeFreed);

               totalAssigned -= allocSizes.remove(idx);
            }
         }
      }

      // free all by cluster
      for (long id = 0; id < maxOwnerId; ++id) {
         final Long ownerId = id;
         networkDao.free(network, ownerId);
      }

      originalBlock = new IpBlockEntity(network, IpBlockEntity.FREE_BLOCK_OWNER_ID,
            BlockType.FREE, beginIp, endIp);
      assertEquals(1, network.getIpBlocks().size());
      assertEquals(originalBlock, network.getIpBlocks().get(0));

      NetworkEntity net = networkDao.findById(network.getId());
View Full Code Here

   @Test
   public void testMergeBasic() {
      NetworkEntity network = new NetworkEntity("net1", "vmnet1", AllocType.IP_POOL,
            "255.255.255.0", "192.168.1.1", "8.8.8.8", null);
      IpBlockEntity blk1 = new IpBlockEntity(network, 1L, BlockType.ASSIGNED, 1L, 3L);
      IpBlockEntity blk2 = new IpBlockEntity(network, 1L, BlockType.ASSIGNED, 4L, 6L);
      IpBlockEntity blk3 = new IpBlockEntity(network, 1L, BlockType.ASSIGNED, 5L, 10L);

      List<IpBlockEntity> split = new ArrayList<IpBlockEntity>();
      split.add(blk1);
      split.add(blk2);
      split.add(blk3);
View Full Code Here

    * groups and join them in a single list and make a final merge. The finally
    * merged list should match to the original one.
    */
   @Test(enabled=false)
   private void doMergeRandomTest(boolean allowOverlap) {
      IpBlockEntity original = new IpBlockEntity(new NetworkEntity("net1", "vmnet1",
            AllocType.IP_POOL, "255.255.255.0", "192.168.1.1", "8.8.8.8", null), 1L,
            BlockType.ASSIGNED, 1L, 1L << 17/* 131072 */);

      List<IpBlockEntity> allBlocks = new ArrayList<IpBlockEntity>();
      for (List<IpBlockEntity> grp : torn(original, 20, allowOverlap)) {
View Full Code Here

   public void testSubtractBasic() {
      NetworkEntity network = new NetworkEntity("net1", "vmnet1", AllocType.IP_POOL,
            "255.255.255.0", "192.168.1.1", "8.8.8.8", null);;

      List<IpBlockEntity> setA = new ArrayList<IpBlockEntity>();
      setA.add(new IpBlockEntity(network, 1L, BlockType.ASSIGNED, 1L, 10L));

      List<IpBlockEntity> setB1 = new ArrayList<IpBlockEntity>();
      setB1.add(new IpBlockEntity(network, 1L, BlockType.ASSIGNED, 1L, 3L));
      List<IpBlockEntity> setB2 = new ArrayList<IpBlockEntity>();
      setB2.add(new IpBlockEntity(network, 1L, BlockType.ASSIGNED, 4L, 6L));
      List<IpBlockEntity> setB3 = new ArrayList<IpBlockEntity>();
      setB3.add(new IpBlockEntity(network, 1L, BlockType.ASSIGNED, 5L, 10L));

      List<IpBlockEntity> setDiff = setA;
      setDiff = IpBlockEntity.subtract(setDiff, setB1);
      setDiff = IpBlockEntity.subtract(setDiff, setB2);
      setDiff = IpBlockEntity.subtract(setDiff, setB3);

      assertTrue(setDiff.isEmpty());

      List<IpBlockEntity> setC = new ArrayList<IpBlockEntity>();
      setC.add(new IpBlockEntity(network, 1L, BlockType.ASSIGNED, 3337306476L, 3337306480L));
      List<IpBlockEntity> setD = new ArrayList<IpBlockEntity>();
      setD.add(new IpBlockEntity(network, 1L, BlockType.ASSIGNED, 3337306476L, 3337306480L));
      setD.add(new IpBlockEntity(network, 1L, BlockType.ASSIGNED, 3337306476L, 3337306476L));
      setDiff = setC;
      setD = ipBlockDao.merge(setD, true, true, true);
      setDiff = IpBlockEntity.subtract(setDiff, setD);

      assertTrue(setDiff.isEmpty());
View Full Code Here

TOP

Related Classes of com.vmware.bdd.entity.IpBlockEntity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.