2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.workflow.tasks;
23 import java.util.List;
24 import java.util.Optional;
25 import org.onap.aai.domain.yang.L3Network;
26 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
27 import org.onap.aaiclient.client.aai.AAIObjectType;
28 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper;
29 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
30 import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.stereotype.Component;
35 public class VrfValidation {
38 protected BBInputSetupUtils bbInputSetupUtils;
40 public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) {
41 this.bbInputSetupUtils = bbInputSetupUtils;
44 protected void vrfServiceValidation(org.onap.so.db.catalog.beans.Service service)
45 throws VrfBondingServiceException {
46 if (!"BONDING".equalsIgnoreCase(service.getServiceType())
47 || !"INFRASTRUCTURE-VPN".equalsIgnoreCase(service.getServiceRole())) {
48 throw new VrfBondingServiceException("Service: " + service.getModelName()
49 + " does not have service type of BONDING and does not have service role of INFRASTRUCTURE-VPN");
53 protected void vrfCatalogDbChecks(org.onap.so.db.catalog.beans.Service service) throws VrfBondingServiceException {
54 ConfigurationResourceCustomization configuration = getVrfConfiguration(service);
55 if (configuration == null || configuration.getServiceProxyResourceCustomization() == null
56 || configuration.getServiceProxyResourceCustomization().getSourceService() == null
57 || !configuration.getServiceProxyResourceCustomization().getSourceService().getServiceType()
58 .equalsIgnoreCase("TRANSPORT")) {
59 throw new VrfBondingServiceException("Service: " + service.getModelName()
60 + " does not have a configuration of type VRF-ENTRY and role INFRASTRUCTURE-CLOUD-VPN"
61 + ", and serviceProxy that does not have source service that has a serviceType of TRANSPORT)");
65 protected ConfigurationResourceCustomization getVrfConfiguration(org.onap.so.db.catalog.beans.Service service) {
66 for (ConfigurationResourceCustomization configuration : service.getConfigurationCustomizations()) {
67 if (configuration.getType() != null && configuration.getType().equalsIgnoreCase("VRF-ENTRY")
68 && configuration.getRole() != null
69 && configuration.getRole().equalsIgnoreCase("INFRASTRUCTURE-CLOUD-VPN")) {
76 protected void aaiVpnBindingValidation(String relatedVpnId, org.onap.aai.domain.yang.VpnBinding aaiVpnBinding)
77 throws VrfBondingServiceException {
78 if (aaiVpnBinding == null) {
79 throw new VrfBondingServiceException("The infrastructure vpn " + relatedVpnId + " does not exist in A&AI.");
80 } else if (aaiVpnBinding.getVpnType() != null
81 && !aaiVpnBinding.getVpnType().equalsIgnoreCase("SERVICE-INFRASTRUCTURE")) {
82 throw new VrfBondingServiceException(
83 "VpnBinding: " + relatedVpnId + " does not have a vpn type of SERVICE-INFRASTRUCTURE.");
87 protected void aaiAggregateRouteValidation(org.onap.aai.domain.yang.L3Network aaiLocalNetwork)
88 throws VrfBondingServiceException {
89 if (aaiLocalNetwork.getAggregateRoutes() == null
90 || aaiLocalNetwork.getAggregateRoutes().getAggregateRoute() == null) {
93 if (aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().size() == 1 && !aaiLocalNetwork
94 .getAggregateRoutes().getAggregateRoute().get(0).getIpVersion().equalsIgnoreCase("4")) {
95 throw new VrfBondingServiceException("LocalNetwork: " + aaiLocalNetwork.getNetworkId()
96 + " has 1 aggregate route but the Ip version of aggregate route is : "
97 + aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().get(0).getIpVersion() + " and is not 4");
98 } else if (aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().size() == 2
99 && !ipVersionValidation(aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().get(0).getIpVersion(),
100 aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().get(1).getIpVersion())) {
101 throw new VrfBondingServiceException("LocalNetwork: " + aaiLocalNetwork.getNetworkId()
102 + " has 2 aggregate routes but the combination of the Ip versions for the aggregate routes did not match the ip version of one of them to be 4 and one to be 6");
103 } else if (aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().size() > 2) {
104 throw new VrfBondingServiceException(
105 "LocalNetwork: " + aaiLocalNetwork.getNetworkId() + " either has more than 2 aggregate routes");
109 protected void aaiNetworkValidation(String relatedNetworkid, org.onap.aai.domain.yang.L3Network aaiLocalNetwork)
110 throws VrfBondingServiceException {
111 if (aaiLocalNetwork == null) {
112 throw new VrfBondingServiceException("The local network " + relatedNetworkid + " does not exist in A&AI.");
116 protected void aaiSubnetValidation(org.onap.aai.domain.yang.L3Network aaiLocalNetwork)
117 throws VrfBondingServiceException {
118 if (aaiLocalNetwork.getSubnets() == null || aaiLocalNetwork.getSubnets().getSubnet() == null) {
119 throw new VrfBondingServiceException("LocalNetwork: " + aaiLocalNetwork.getNetworkId() + " has no subnets");
120 } else if (aaiLocalNetwork.getSubnets().getSubnet().size() == 1
121 && !aaiLocalNetwork.getSubnets().getSubnet().get(0).getIpVersion().equalsIgnoreCase("4")) {
122 throw new VrfBondingServiceException("LocalNetwork: " + aaiLocalNetwork.getNetworkId()
123 + " has 1 subnet but the Ip version of subnet is : "
124 + aaiLocalNetwork.getSubnets().getSubnet().get(0).getIpVersion() + " and is not 4");
125 } else if (aaiLocalNetwork.getSubnets().getSubnet().size() == 2
126 && !ipVersionValidation(aaiLocalNetwork.getSubnets().getSubnet().get(0).getIpVersion(),
127 aaiLocalNetwork.getSubnets().getSubnet().get(1).getIpVersion())) {
128 throw new VrfBondingServiceException("LocalNetwork: " + aaiLocalNetwork.getNetworkId()
129 + " has 2 subnets but the combination of the Ip versions for the subnets did not match the ip version of one of them to be 4 and one to be 6");
130 } else if (aaiLocalNetwork.getSubnets().getSubnet().isEmpty()
131 || aaiLocalNetwork.getSubnets().getSubnet().size() > 2) {
132 throw new VrfBondingServiceException("LocalNetwork: " + aaiLocalNetwork.getNetworkId()
133 + " either has no subnets or more than 2 subnets");
137 protected boolean ipVersionValidation(String ipVersion1, String ipVersion2) {
138 return (ipVersion1.equalsIgnoreCase("4") && ipVersion2.equalsIgnoreCase("6"))
139 || (ipVersion1.equalsIgnoreCase("6") && ipVersion2.equalsIgnoreCase("4"));
142 protected void aaiRouteTargetValidation(L3Network aaiLocalNetwork) throws VrfBondingServiceException {
143 AAIResultWrapper networkWrapper = new AAIResultWrapper(aaiLocalNetwork);
144 if (networkWrapper.getRelationships().isPresent()) {
145 List<AAIResourceUri> vpnBindingUris =
146 networkWrapper.getRelationships().get().getRelatedUris(AAIObjectType.VPN_BINDING);
147 if (!vpnBindingUris.isEmpty()) {
148 Optional<org.onap.aai.domain.yang.VpnBinding> vpnBindingOp =
149 bbInputSetupUtils.getAAIResourceDepthOne(vpnBindingUris.get(0))
150 .asBean(org.onap.aai.domain.yang.VpnBinding.class);
151 if (vpnBindingOp.isPresent()) {
152 org.onap.aai.domain.yang.VpnBinding vpnBinding = vpnBindingOp.get();
153 if (vpnBinding.getRouteTargets() != null
154 && !vpnBinding.getRouteTargets().getRouteTarget().isEmpty()) {
160 throw new VrfBondingServiceException("The Local Network: " + aaiLocalNetwork.getNetworkId()
161 + " does not have vpn binding and/or RT information");