示例#1
0
  /**
   * Returns first vlan in vlanRange that is free in given interface of given router, and it's not
   * in given suggestedVLANs. After this call, returned vlan is already included in suggestedVLANs.
   *
   * @param phyElement
   * @param phyIface
   * @param suggestedVLANs
   * @return
   * @return first vlan in vlanRange that is free in given interface of given router, and it's not
   *     in given suggestedVLANs
   * @throws VCPENetworkManagerException if there is no available vlan in specified vlanRange
   */
  public static int suggestVLAN(
      VCPENetworkElement phyElement, Interface phyIface, SuggestedValues suggestedVLANs)
      throws VCPENetworkManagerException {

    List<Integer> candidates = getVLANs(phyElement, phyIface);
    Integer selectedVlan = null;
    for (Integer vlan : candidates) {
      if (!suggestedVLANs.isAlreadySuggested(
          VCPENetworkModelHelper.generatePhysicalInterfaceKey(phyElement, phyIface), vlan)) {
        if (IsFreeChecker.isVLANFree(
            null,
            phyElement.getName(),
            Integer.toString(vlan),
            phyIface.getPhysicalInterfaceName())) {
          selectedVlan = vlan;
          break;
        }
      }
    }
    if (selectedVlan == null)
      throw new VCPENetworkManagerException(
          "Unable to find an available vlan for interface "
              + VCPENetworkModelHelper.generatePhysicalInterfaceKey(phyElement, phyIface));

    suggestedVLANs.markAsSuggested(
        VCPENetworkModelHelper.generatePhysicalInterfaceKey(phyElement, phyIface), selectedVlan);

    return selectedVlan;
  }
示例#2
0
  public static int suggestVLANWithPreference(
      VCPENetworkElement phyElement,
      Interface phyIface,
      SuggestedValues suggestedVLANs,
      int preferredVlan)
      throws VCPENetworkManagerException {

    if (!suggestedVLANs.isAlreadySuggested(
        VCPENetworkModelHelper.generatePhysicalInterfaceKey(phyElement, phyIface), preferredVlan)) {
      if (IsFreeChecker.isVLANFree(
          null,
          phyElement.getName(),
          Integer.toString(preferredVlan),
          phyIface.getPhysicalInterfaceName())) {
        suggestedVLANs.markAsSuggested(
            VCPENetworkModelHelper.generatePhysicalInterfaceKey(phyElement, phyIface),
            preferredVlan);
        return preferredVlan;
      }
    }

    return suggestVLAN(phyElement, phyIface, suggestedVLANs);
  }