Ejemplo n.º 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;
  }
Ejemplo n.º 2
0
  /**
   * Sets iface vlan according to the other endpoint of given link.
   *
   * @param phyElement
   * @param iface
   * @param link
   * @param suggestedVLANS
   */
  private void updateIfaceVLANFromLink(
      VCPENetworkElement phyElement, Interface iface, Link link, SuggestedValues suggestedVLANs) {
    long vlan = VCPENetworkModelHelper.updateIfaceVLANFromLink(iface, link);

    suggestedVLANs.markAsSuggested(
        VCPENetworkModelHelper.generatePhysicalInterfaceKey(phyElement, iface),
        Long.valueOf(vlan).intValue());
  }
 private VCPENetworkModel hierarchicalLRnames(VCPENetworkModel model) {
   for (LogicalRouter lr :
       Iterables.filter(
           VCPENetworkModelHelper.getRouters(model.getElements()), LogicalRouter.class)) {
     lr.setName(model.getName() + "-" + lr.getName());
   }
   return model;
 }
  private VCPENetworkModel configureRouting(VCPENetworkModel model) {
    // reset routing configuration for LRs
    for (LogicalRouter lr :
        Iterables.filter(
            VCPENetworkModelHelper.getRouters(model.getElements()), LogicalRouter.class)) {
      lr.setRoutingConfiguration(new RoutingConfiguration());
    }

    configureStaticRoutes(model);
    return model;
  }
  /**
   * Copies data in elements from given source to elements in given destination with same
   * templateName. No element is created within this method. Does not copy references to other
   * elements (interfaces, physicalRouter, etc.)
   *
   * @param source
   * @param destination
   * @return destination updated with values in source.
   */
  private VCPENetworkModel partialCopy(VCPENetworkModel source, VCPENetworkModel destination) {
    destination.setName(source.getName());
    destination.setId(source.getId());

    VCPENetworkElement dstElement;
    for (VCPENetworkElement srcElement : source.getElements()) {
      dstElement =
          VCPENetworkModelHelper.getElementByTemplateName(
              destination.getElements(), srcElement.getTemplateName());
      if (dstElement != null) {
        dstElement.setName(srcElement.getName());
        if (srcElement instanceof Interface && dstElement instanceof Interface) {
          VCPENetworkModelHelper.copyInterface((Interface) dstElement, (Interface) srcElement);
        } else if (srcElement instanceof IPNetworkDomain && dstElement instanceof IPNetworkDomain) {
          ((IPNetworkDomain) dstElement).setOwner(((IPNetworkDomain) srcElement).getOwner());
          ((IPNetworkDomain) dstElement).setASNumber(((IPNetworkDomain) srcElement).getASNumber());
          ((IPNetworkDomain) dstElement)
              .setIPAddressRanges(((IPNetworkDomain) srcElement).getIPAddressRanges());
        }
      }
    }
    return destination;
  }
Ejemplo n.º 6
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);
  }
  /**
   * Creates MP-template required static routes in given model.
   *
   * <p>Creates following static routes:
   *
   * <p>in LR1: <br>
   * static route LAN_CLIENT.getIPAddressRange() next-hop LR_CLIENT_IFACE_UP1.getIPAddress()
   * (through LR_1_IFACE_DOWN) <br>
   * static route 0.0.0.0/0 next-hop WAN1_IFACE_DOWN.getIPAddress() (through LR_1_IFACE_UP) <br>
   * in LR2: <br>
   * static route LAN_CLIENT.getIPAddressRange() next-hop LR_CLIENT_IFACE_UP2.getIPAddress()
   * (through LR_2_IFACE_DOWN) <br>
   * static route 0.0.0.0/0 next-hop WAN2_IFACE_DOWN.getIPAddress() (through LR_2_IFACE_UP) <br>
   * in LR_CLIENT: <br>
   * static route LAN_CLIENT.getIPAddressRange() next-hop LAN_CLIENT_IFACE_UP.getIPAddress()
   * (through LR_CLIENT_IFACE_DOWN) <br>
   * static route WAN1.getIPAddressRange() next-hop LR_1_IFACE_DOWN.getIPAddress() (through
   * LR_CLIENT_IFACE_UP1) <br>
   * static route WAN2.getIPAddressRange() next-hop LR_2_IFACE_DOWN.getIPAddress() (through
   * LR_CLIENT_IFACE_UP2) <br>
   * static route 0.0.0.0/0 next-hop LR_1_IFACE_DOWN.getIPAddress() (through LR_CLIENT_IFACE_UP1)
   * //default provider is WAN1 <br>
   * Documented in issue OPENNAAS-869.
   *
   * @param model
   * @return given model with required static routes included
   */
  private VCPENetworkModel configureStaticRoutes(VCPENetworkModel model) {

    String allRoutes = "0.0.0.0/0";
    RoutingConfiguration config;

    List<String> clientIPRanges =
        ((IPNetworkDomain)
                VCPENetworkModelHelper.getElementByTemplateName(
                    model, TemplateConstants.LAN_CLIENT))
            .getIPAddressRanges();
    List<String> wan1IPRanges =
        ((IPNetworkDomain)
                VCPENetworkModelHelper.getElementByTemplateName(model, TemplateConstants.WAN1))
            .getIPAddressRanges();
    List<String> wan2IPRanges =
        ((IPNetworkDomain)
                VCPENetworkModelHelper.getElementByTemplateName(model, TemplateConstants.WAN2))
            .getIPAddressRanges();

    // LR_1
    config =
        ((Router)
                VCPENetworkModelHelper.getElementByTemplateName(
                    model, TemplateConstants.LR_1_ROUTER))
            .getRoutingConfiguration();
    config.setStaticRoutes(new ArrayList<StaticRouteConfiguration>(2));

    // static route LAN_CLIENT.getIPAddressRange() next-hop LR_CLIENT_IFACE_UP1.getIPAddress()
    // (through LR_1_IFACE_DOWN)
    for (String ipRange : clientIPRanges) {
      config
          .getStaticRoutes()
          .add(
              new StaticRouteConfiguration(
                  ipRange,
                  ((Interface)
                          VCPENetworkModelHelper.getElementByTemplateName(
                              model, TemplateConstants.LR_CLIENT_IFACE_UP1))
                      .getIpAddress(),
                  false));
    }
    // static route 0.0.0.0/0 next-hop WAN1_IFACE_DOWN.getIPAddress() (through LR_1_IFACE_UP)
    config
        .getStaticRoutes()
        .add(
            new StaticRouteConfiguration(
                allRoutes,
                ((Interface)
                        VCPENetworkModelHelper.getElementByTemplateName(
                            model, TemplateConstants.WAN1_IFACE_DOWN))
                    .getIpAddress(),
                false));

    // LR_2
    config =
        ((Router)
                VCPENetworkModelHelper.getElementByTemplateName(
                    model, TemplateConstants.LR_2_ROUTER))
            .getRoutingConfiguration();
    config.setStaticRoutes(new ArrayList<StaticRouteConfiguration>(2));
    // static route LAN_CLIENT.getIPAddressRange() next-hop LR_CLIENT_IFACE_UP2.getIPAddress()
    // (through LR_2_IFACE_DOWN)
    for (String ipRange : clientIPRanges) {
      config
          .getStaticRoutes()
          .add(
              new StaticRouteConfiguration(
                  ipRange,
                  ((Interface)
                          VCPENetworkModelHelper.getElementByTemplateName(
                              model, TemplateConstants.LR_CLIENT_IFACE_UP2))
                      .getIpAddress(),
                  false));
    }
    // static route 0.0.0.0/0 next-hop WAN2_IFACE_DOWN.getIPAddress() (through LR_2_IFACE_UP)
    config
        .getStaticRoutes()
        .add(
            new StaticRouteConfiguration(
                allRoutes,
                ((Interface)
                        VCPENetworkModelHelper.getElementByTemplateName(
                            model, TemplateConstants.WAN2_IFACE_DOWN))
                    .getIpAddress(),
                false));

    // LR_CLIENT
    config =
        ((Router)
                VCPENetworkModelHelper.getElementByTemplateName(
                    model, TemplateConstants.LR_CLIENT_ROUTER))
            .getRoutingConfiguration();
    config.setStaticRoutes(new ArrayList<StaticRouteConfiguration>(4));
    // static route LAN_CLIENT.getIPAddressRange() next-hop LAN_CLIENT_IFACE_UP.getIPAddress()
    // (through LR_CLIENT_IFACE_DOWN)
    for (String ipRange : clientIPRanges) {
      config
          .getStaticRoutes()
          .add(
              new StaticRouteConfiguration(
                  ipRange,
                  ((Interface)
                          VCPENetworkModelHelper.getElementByTemplateName(
                              model, TemplateConstants.LAN_CLIENT_IFACE_UP))
                      .getIpAddress(),
                  false));
    }
    // static route WAN1.getIPAddressRange() next-hop LR_1_IFACE_DOWN.getIPAddress() (through
    // LR_CLIENT_IFACE_UP1)
    for (String ipRange : wan1IPRanges) {
      config
          .getStaticRoutes()
          .add(
              new StaticRouteConfiguration(
                  ipRange,
                  ((Interface)
                          VCPENetworkModelHelper.getElementByTemplateName(
                              model, TemplateConstants.LR_1_IFACE_DOWN))
                      .getIpAddress(),
                  false));
    }
    // static route WAN2.getIPAddressRange() next-hop LR_2_IFACE_DOWN.getIPAddress() (through
    // LR_CLIENT_IFACE_UP2)
    for (String ipRange : wan2IPRanges) {
      config
          .getStaticRoutes()
          .add(
              new StaticRouteConfiguration(
                  ipRange,
                  ((Interface)
                          VCPENetworkModelHelper.getElementByTemplateName(
                              model, TemplateConstants.LR_2_IFACE_DOWN))
                      .getIpAddress(),
                  false));
    }
    // static route 0.0.0.0/0 next-hop LR_1_IFACE_DOWN.getIPAddress() (through LR_CLIENT_IFACE_UP1)
    // //default provider is WAN1
    config
        .getStaticRoutes()
        .add(
            new StaticRouteConfiguration(
                allRoutes,
                ((Interface)
                        VCPENetworkModelHelper.getElementByTemplateName(
                            model, TemplateConstants.LR_1_IFACE_DOWN))
                    .getIpAddress(),
                false));

    return model;
  }
Ejemplo n.º 8
0
  private VCPENetworkModel suggestVLANs(
      VCPENetworkModel physicalModel, VCPENetworkModel logicalModel) {

    Integer vlan;
    VCPENetworkElement phyElement;
    Interface phyIface;
    Interface target;

    SuggestedValues suggestedVLANs = new SuggestedValues();

    // suggest VLANs for router interfaces
    phyElement =
        (Router)
            VCPENetworkModelHelper.getElementByTemplateName(
                physicalModel, TemplateConstants.ROUTER_1_PHY);
    phyIface =
        (Interface)
            VCPENetworkModelHelper.getElementByTemplateName(
                physicalModel, TemplateConstants.ROUTER_1_PHY_IFACE_UP1);
    target =
        (Interface)
            VCPENetworkModelHelper.getElementByTemplateName(
                logicalModel, TemplateConstants.LR_1_IFACE_UP);
    vlan =
        VLANSuggestor.suggestVLANWithPreference(
            phyElement, phyIface, suggestedVLANs, Long.valueOf(target.getVlan()).intValue());
    target.setVlan(vlan);

    phyElement =
        (Router)
            VCPENetworkModelHelper.getElementByTemplateName(
                physicalModel, TemplateConstants.ROUTER_1_PHY);
    phyIface =
        (Interface)
            VCPENetworkModelHelper.getElementByTemplateName(
                physicalModel, TemplateConstants.ROUTER_1_PHY_IFACE_UP2);
    target =
        (Interface)
            VCPENetworkModelHelper.getElementByTemplateName(
                logicalModel, TemplateConstants.LR_2_IFACE_UP);
    vlan =
        VLANSuggestor.suggestVLANWithPreference(
            phyElement, phyIface, suggestedVLANs, Long.valueOf(target.getVlan()).intValue());
    target.setVlan(vlan);

    phyElement =
        (Router)
            VCPENetworkModelHelper.getElementByTemplateName(
                physicalModel, TemplateConstants.ROUTER_1_PHY);
    phyIface =
        (Interface)
            VCPENetworkModelHelper.getElementByTemplateName(
                physicalModel, TemplateConstants.ROUTER_1_PHY_IFACE_DOWN);
    target =
        (Interface)
            VCPENetworkModelHelper.getElementByTemplateName(
                logicalModel, TemplateConstants.LR_CLIENT_IFACE_DOWN);
    vlan =
        VLANSuggestor.suggestVLANWithPreference(
            phyElement, phyIface, suggestedVLANs, Long.valueOf(target.getVlan()).intValue());
    target.setVlan(vlan);

    // update other endpoints of links with same vlans
    Link link;
    IPNetworkDomain net;

    target =
        (Interface)
            VCPENetworkModelHelper.getElementByTemplateName(
                logicalModel, TemplateConstants.WAN1_IFACE_DOWN);
    link =
        (Link)
            VCPENetworkModelHelper.getElementByTemplateName(
                logicalModel, TemplateConstants.LINK_WAN1);
    net =
        (IPNetworkDomain)
            VCPENetworkModelHelper.getElementByTemplateName(logicalModel, TemplateConstants.WAN1);
    // Passing a logical element where a physical one is expected
    updateIfaceVLANFromLink(net, target, link, suggestedVLANs);

    target =
        (Interface)
            VCPENetworkModelHelper.getElementByTemplateName(
                logicalModel, TemplateConstants.WAN2_IFACE_DOWN);
    link =
        (Link)
            VCPENetworkModelHelper.getElementByTemplateName(
                logicalModel, TemplateConstants.LINK_WAN2);
    net =
        (IPNetworkDomain)
            VCPENetworkModelHelper.getElementByTemplateName(logicalModel, TemplateConstants.WAN2);
    // Passing a logical element where a physical one is expected
    updateIfaceVLANFromLink(net, target, link, suggestedVLANs);

    target =
        (Interface)
            VCPENetworkModelHelper.getElementByTemplateName(
                logicalModel, TemplateConstants.LAN_CLIENT_IFACE_UP);
    link =
        (Link)
            VCPENetworkModelHelper.getElementByTemplateName(
                logicalModel, TemplateConstants.LINK_LAN_CLIENT);
    net =
        (IPNetworkDomain)
            VCPENetworkModelHelper.getElementByTemplateName(
                logicalModel, TemplateConstants.LAN_CLIENT);
    // Passing a logical element where a physical one is expected
    updateIfaceVLANFromLink(net, target, link, suggestedVLANs);

    return logicalModel;
  }
Ejemplo n.º 9
0
  private VCPENetworkModel suggestUnits(
      VCPENetworkModel physicalModel, VCPENetworkModel logicalModel) {

    VCPENetworkElement phyElement;
    IPNetworkDomain net;
    Interface target;
    Integer unit;

    SuggestedValues suggestedUnits = new SuggestedValues();

    // Suggest units from vlans

    phyElement =
        (Router)
            VCPENetworkModelHelper.getElementByTemplateName(
                physicalModel, TemplateConstants.ROUTER_1_PHY);

    target =
        (Interface)
            VCPENetworkModelHelper.getElementByTemplateName(
                logicalModel, TemplateConstants.LR_1_IFACE_UP);
    unit = UnitSuggestor.suggestUnitFromVLAN(phyElement, target, suggestedUnits);
    target.setPort(unit);

    target =
        (Interface)
            VCPENetworkModelHelper.getElementByTemplateName(
                logicalModel, TemplateConstants.LR_2_IFACE_UP);
    unit = UnitSuggestor.suggestUnitFromVLAN(phyElement, target, suggestedUnits);
    target.setPort(unit);

    target =
        (Interface)
            VCPENetworkModelHelper.getElementByTemplateName(
                logicalModel, TemplateConstants.LR_CLIENT_IFACE_DOWN);
    unit = UnitSuggestor.suggestUnitFromVLAN(phyElement, target, suggestedUnits);
    target.setPort(unit);

    net =
        (IPNetworkDomain)
            VCPENetworkModelHelper.getElementByTemplateName(logicalModel, TemplateConstants.WAN1);
    target =
        (Interface)
            VCPENetworkModelHelper.getElementByTemplateName(
                logicalModel, TemplateConstants.WAN1_IFACE_DOWN);
    unit = UnitSuggestor.suggestUnitFromVLAN(net, target, suggestedUnits);
    target.setPort(unit);

    net =
        (IPNetworkDomain)
            VCPENetworkModelHelper.getElementByTemplateName(logicalModel, TemplateConstants.WAN2);
    target =
        (Interface)
            VCPENetworkModelHelper.getElementByTemplateName(
                logicalModel, TemplateConstants.WAN2_IFACE_DOWN);
    unit = UnitSuggestor.suggestUnitFromVLAN(net, target, suggestedUnits);
    target.setPort(unit);

    net =
        (IPNetworkDomain)
            VCPENetworkModelHelper.getElementByTemplateName(
                logicalModel, TemplateConstants.LAN_CLIENT);
    target =
        (Interface)
            VCPENetworkModelHelper.getElementByTemplateName(
                logicalModel, TemplateConstants.LAN_CLIENT_IFACE_UP);
    unit = UnitSuggestor.suggestUnitFromVLAN(net, target, suggestedUnits);
    target.setPort(unit);

    // Suggest units for LTs
    Link lt1 =
        (Link)
            VCPENetworkModelHelper.getElementByTemplateName(
                logicalModel, TemplateConstants.LINK_LR_1_LR_CLIENT);
    Link lt2 =
        (Link)
            VCPENetworkModelHelper.getElementByTemplateName(
                logicalModel, TemplateConstants.LINK_LR_2_LR_CLIENT);

    lt1.getSource().setPort(UnitSuggestor.suggestUnit(phyElement, lt1.getSource(), suggestedUnits));
    lt1.getSink().setPort(UnitSuggestor.suggestUnit(phyElement, lt1.getSink(), suggestedUnits));

    lt2.getSource().setPort(UnitSuggestor.suggestUnit(phyElement, lt2.getSource(), suggestedUnits));
    lt2.getSink().setPort(UnitSuggestor.suggestUnit(phyElement, lt2.getSink(), suggestedUnits));

    // Suggest units for LOs
    target =
        (Interface)
            VCPENetworkModelHelper.getElementByTemplateName(
                logicalModel, TemplateConstants.LR_1_IFACE_LO);
    target.setPort(UnitSuggestor.suggestUnit(phyElement, target, suggestedUnits));

    target =
        (Interface)
            VCPENetworkModelHelper.getElementByTemplateName(
                logicalModel, TemplateConstants.LR_2_IFACE_LO);
    target.setPort(UnitSuggestor.suggestUnit(phyElement, target, suggestedUnits));

    target =
        (Interface)
            VCPENetworkModelHelper.getElementByTemplateName(
                logicalModel, TemplateConstants.LR_CLIENT_IFACE_LO);
    target.setPort(UnitSuggestor.suggestUnit(phyElement, target, suggestedUnits));

    return logicalModel;
  }