Package com.vmware.bdd.entity

Examples of com.vmware.bdd.entity.NetworkEntity


      networkSvc = new MockUp<INetworkService>() {
         @Mock
         NetworkEntity addDhcpNetwork(final String name, final String portGroup) {
            Assert.assertEquals(name, "defaultNetwork");
            Assert.assertEquals(portGroup, "serengetiNet");
            return new NetworkEntity();
         }
      }.getMockInstance();
      service.setRpSvc(rpSvc);
      service.setDsSvc(dsSvc);
      service.setNetworkSvc(networkSvc);
View Full Code Here


      if(dss != null && dss.size() > 0){
         for(VcDatastoreEntity ds : dss){
            dsDao.delete(ds);
         }
      }
      NetworkEntity network = networkDao.findNetworkByName(ResourceInitializerService.DEFAULT_NETWORK);
      if(network != null){
         networkDao.delete(network);
      }
      svc.initResource();
View Full Code Here

      final String netmask = "255.255.255.0";
      final String gateway = "192.168.1.254";
      final String dns1 = "8.8.8.8";
      final String dns2 = "4.4.4.4";

      NetworkEntity network = new NetworkEntity(portGroup, portGroup, allocType,
            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);

      NetworkEntity network2 = networkDao.findById(network.getId());
      assertNotNull(network2);

      NetworkEntity net = networkDao.findById(network.getId());

      networkDao.delete(net);

      assertNull(networkDao.findById(network.getId()));

View Full Code Here

      final Long beginIp = IpAddressUtil.getAddressAsLong(InetAddress
            .getByName("0.0.0.2"));
      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());

      networkDao.delete(net);
      logger.info("alloc/free test done");
   }
View Full Code Here

      return str;
   }

   private List<IpBlockEntity> genRandBlocks(int count) {
      List<IpBlockEntity> blocks = new ArrayList<IpBlockEntity>(count);
      NetworkEntity network = new NetworkEntity("net1", "vmnet1", AllocType.IP_POOL,
            "255.255.255.0", "192.168.1.1", "8.8.8.8", null);

      Long[] owners = { 1L, 2L, 3L, 4L, 5L };
      BlockType[] blockTypes = { BlockType.ASSIGNED, BlockType.FREE };
View Full Code Here

      assertTrue(count >= N);
   }

   @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);
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

      doMergeRandomTest(false);
   }

   @Test
   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));
View Full Code Here

    * pieces and then subtract the original block with all these pieces one by
    * one. Finally the result diff will equals to en empty set.
    */
   @Test(enabled=false)
   private void doSubtractRandomTest(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 << 15);

      List<IpBlockEntity> setA = new ArrayList<IpBlockEntity>();
      setA.add(original);
View Full Code Here

      Set<NicSpec.NetTrafficDefinition> netDefs3 = new HashSet<NicSpec.NetTrafficDefinition>();
      netDefs3.add(netDef3);

      NicEntity nic1 = new NicEntity();
      NetworkEntity net1 = new NetworkEntity();
      net1.setPortGroup("pg1");
      net1.setName("net1");
      nic1.setIpv4Address("192.168.0.1");
      nic1.setNetTrafficDefs(netDefs1);
      nic1.setNetworkEntity(net1);

      NicEntity nic2 = new NicEntity();
      nic2.setIpv4Address("192.168.1.1");
      nic2.setNetTrafficDefs(netDefs2);
      NetworkEntity net2 = new NetworkEntity();
      net2.setPortGroup("pg2");
      net2.setName("net2");
      nic2.setNetworkEntity(net2);

      NicEntity nic3 = new NicEntity();
      nic3.setIpv4Address("192.168.2.1");
      nic3.setNetTrafficDefs(netDefs3);
      NetworkEntity net3 = new NetworkEntity();
      net3.setPortGroup("pg3");
      net3.setName("net3");
      nic3.setNetworkEntity(net3);

      nicEntitySet.add(nic1);
      nicEntitySet.add(nic2);
      nicEntitySet.add(nic3);
View Full Code Here

TOP

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

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.