/** * 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; }
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); }
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; }
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; }