2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 ONAP Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.openecomp.sdnc.ra.check;
26 import org.openecomp.sdnc.ra.comp.EquipmentCheck;
27 import org.openecomp.sdnc.ra.comp.ServiceData;
28 import org.openecomp.sdnc.ra.equip.data.EquipmentData;
29 import org.openecomp.sdnc.rm.comp.ResourceManager;
30 import org.openecomp.sdnc.rm.data.AllocationItem;
31 import org.openecomp.sdnc.rm.data.Resource;
32 import org.openecomp.sdnc.util.vrf.VpnParam;
33 import org.openecomp.sdnc.util.vrf.VrfUtil;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 public class OneMVrfCheck implements EquipmentCheck {
39 private static final Logger log = LoggerFactory.getLogger(OneMVrfCheck.class);
41 private ResourceManager resourceManager;
44 public boolean checkEquipment(
45 String endPointPosition,
46 ServiceData serviceData,
47 EquipmentData equipData,
48 Map<String, Object> equipmentConstraints) {
49 String vrfName = (String) serviceData.data.get("vrf-name");
53 String v4MulticastStr = (String) serviceData.data.get("v4-multicast");
54 String v6MulticastStr = (String) serviceData.data.get("v6-multicast");
55 boolean v4Multicast = v4MulticastStr != null &&
56 (v4MulticastStr.equalsIgnoreCase("Y") || v4MulticastStr.equalsIgnoreCase("true"));
57 boolean v6Multicast = v6MulticastStr != null &&
58 (v6MulticastStr.equalsIgnoreCase("Y") || v6MulticastStr.equalsIgnoreCase("true"));
59 if (!v4Multicast && !v6Multicast)
62 // First check if a new VRF would be required. If not, we are good
63 Resource r = resourceManager.getResource("VRF", equipData.equipmentId);
64 if (r != null && r.allocationItems != null)
65 for (AllocationItem ai : r.allocationItems)
66 if (ai.resourceShareGroupList.contains(vrfName))
69 String resourceUnionId = serviceData.serviceInstanceId + '/' + serviceData.endPointPosition;
71 // Check if there is already another multicast VRF for the same VPN
72 VpnParam vpnp = VrfUtil.parseVrfInstanceName(vrfName);
73 r = resourceManager.getResource("MVRF", equipData.equipmentId);
74 if (r != null && r.allocationItems != null) {
75 for (AllocationItem ai : r.allocationItems) {
77 // Skip the allocation item for the current service instance, if there, in case it is a change order
78 if (ai.resourceUnionId.equals(resourceUnionId))
81 if (ai.resourceShareGroupList != null && ai.resourceShareGroupList.size() > 0) {
82 String vrfName2 = ai.resourceShareGroupList.iterator().next();
83 VpnParam vpnp2 = VrfUtil.parseVrfInstanceName(vrfName2);
84 if (vpnp.vpnId.equals(vpnp2.vpnId)) {
85 log.info("Skipping VPE " + equipData.equipmentId +
86 ": This request requires new multicast VRF, " +
87 "but there is already another multicast VRF for the same VPN: " + vrfName2 + ".");
97 public void setResourceManager(ResourceManager resourceManager) {
98 this.resourceManager = resourceManager;