public String getFederatedRange(ClaudiaData data, String region) throws InfrastructureException {

    int cidrdb = networkInstanceManager.findAll().size();
    int cidrOpenstack = networkInstanceManager.getNumberDeployedNetwork(data, region);
    int cidrCount = cidrdb + cidrOpenstack;
    return "155.0." + cidrCount;
  }
  /**
   * it deletes the networks from the environment if they are not used.
   *
   * @param claudiaData
   * @param tierInstance
   * @throws InvalidEntityException
   * @throws InfrastructureException
   * @throws EntityNotFoundException
   */
  @Override
  public void deleteNetworksInTierInstance(ClaudiaData claudiaData, TierInstance tierInstance)
      throws InvalidEntityException, InfrastructureException, EntityNotFoundException {
    log.info("Delete the networks in env if there are not being used");

    List<NetworkInstance> netInsts = null;
    try {
      netInsts = getNetworkInstInEnv(tierInstance);
    } catch (EntityNotFoundException e) {
      throw new InfrastructureException("It is not possible to find the network " + e.getMessage());
    }

    tierInstance.getNetworkInstances().clear();
    tierInstanceManager.update(tierInstance);
    for (NetworkInstance network : netInsts) {
      log.info("Is network default? " + network.isDefaultNet());

      if (!network.isDefaultNet()) {
        try {
          networkInstanceManager.delete(claudiaData, network, network.getRegionName());
        } catch (Exception e) {
          log.warn(
              "It is not possible to delete  the network "
                  + network.getNetworkName()
                  + " "
                  + network.getRegionName()
                  + " "
                  + e.getMessage());
        }
      }
    }
  }
  public void federatedNetworks(ClaudiaData data, EnvironmentInstance environmentInstance)
      throws InfrastructureException {
    log.info("Federate networks in the enviornment");
    // Get the networks to be federated

    Set<String> federatedNetworks = environmentInstance.getEnvironment().getFederatedNetworks();
    Map<String, Set<String>> relation = environmentInstance.getEnvironment().getNetworksRegion();
    List<NetworkInstance> networkInstances = new ArrayList<NetworkInstance>();

    for (String net : federatedNetworks) {
      log.info("Network in the federated network " + net);
      Set<String> regions = relation.get(net);
      log.info("regions " + regions);

      for (String region : regions) {
        log.info("region " + region);
        NetworkInstance netInstance =
            environmentInstance.getNetworkInstanceFromNetwork(net, region);
        log.info(
            "net  "
                + netInstance.getNetworkName()
                + " "
                + netInstance.getIdNetwork()
                + " for region "
                + region);
        if (netInstance != null) {
          networkInstances.add(netInstance);
        }
      }
    }
    try {
      networkInstanceManager.joinNetwork(data, networkInstances.get(0), networkInstances.get(1));
    } catch (Exception e) {
      String mens = "Error federating networks  :" + e.getMessage();
      throw new InfrastructureException(mens);
    }
  }
  /**
   * It deploys the required networks.
   *
   * @param data
   * @param tierInstance
   * @throws InvalidEntityException
   * @throws InfrastructureException
   * @throws EntityNotFoundException
   */
  public void deployNetworks(ClaudiaData data, TierInstance tierInstance)
      throws InvalidEntityException, InfrastructureException, EntityNotFoundException,
          AlreadyExistsEntityException {
    Tier tier = tierInstance.getTier();
    tier =
        tierManager.loadTierWithNetworks(tier.getName(), data.getVdc(), tier.getEnviromentName());
    // Creating networks...
    log.info(
        "Deploying network for tier instance "
            + tierInstance.getName()
            + " "
            + tier.getNetworks().size()
            + " region "
            + tier.getRegion());
    List<Network> networkToBeDeployed = new ArrayList<Network>();
    for (Network network : tier.getNetworks()) {
      log.info("Network to be added " + network.getNetworkName());
      if (network.getNetworkName().equals("Internet")) {

        tier.setFloatingip("true");
        tier = tierManager.update(tier);
        tierInstance.update(tier);
      } else {
        networkToBeDeployed.add(network);
      }
    }

    for (Network network : networkToBeDeployed) {
      log.info(
          "Network instance to be deployed: "
              + network.getNetworkName()
              + " vdc "
              + data.getVdc()
              + " "
              + network.getRegion()
              + " and federated "
              + network.getfederatedNetwork());
      network = networkManager.load(network.getNetworkName(), data.getVdc(), network.getRegion());
      NetworkInstance networkInst = network.toNetworkInstance();
      log.info(
          "Network instance to be deployed: "
              + network.getNetworkName()
              + " vdc "
              + data.getVdc()
              + " region "
              + networkInst.getRegionName()
              + " and networkInst "
              + network.getfederatedNetwork());

      if (networkInstanceManager.exists(data, networkInst, tier.getRegion())) {
        log.info("the network inst " + networkInst.getNetworkName() + " already exists");
        networkInst =
            networkInstanceManager.load(networkInst.getNetworkName(), data, tier.getRegion());
      } else {
        try {
          log.info("the network inst " + networkInst.getNetworkName() + " do not exists");
          networkInst =
              networkInstanceManager.create(data, networkInst, tierInstance.getTier().getRegion());
        } catch (AlreadyExistsEntityException e2) {
          throw new InvalidEntityException(network);
        } catch (InfrastructureException e) {
          String mens =
              "Error to deploy a network " + network.getNetworkName() + " :" + e.getMessage();
          throw new InfrastructureException(mens);
        }
      }
      log.info("Adding network to tier isntance " + networkInst.getNetworkName());
      tierInstance.addNetworkInstance(networkInst);
    }
  }