aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VrfValidation.java
blob: 3b54645b35fac1cab3a8545253953c9182a21d3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*-
 * ============LICENSE_START=======================================================
 * ONAP - SO
 * ================================================================================
 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader;

import java.util.List;
import java.util.Optional;
import org.onap.aai.domain.yang.L3Network;
import org.onap.aaiclient.client.aai.entities.AAIResultWrapper;
import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types;
import org.onap.so.bpmn.infrastructure.workflow.tasks.VrfBondingServiceException;
import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class VrfValidation {

    @Autowired
    protected BBInputSetupUtils bbInputSetupUtils;

    public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) {
        this.bbInputSetupUtils = bbInputSetupUtils;
    }

    protected void vrfServiceValidation(org.onap.so.db.catalog.beans.Service service)
            throws VrfBondingServiceException {
        if (!"BONDING".equalsIgnoreCase(service.getServiceType())
                || !"INFRASTRUCTURE-VPN".equalsIgnoreCase(service.getServiceRole())) {
            throw new VrfBondingServiceException("Service: " + service.getModelName()
                    + " does not have service type of BONDING and does not have service role of INFRASTRUCTURE-VPN");
        }
    }

    protected void vrfCatalogDbChecks(org.onap.so.db.catalog.beans.Service service) throws VrfBondingServiceException {
        ConfigurationResourceCustomization configuration = getVrfConfiguration(service);
        if (configuration == null || configuration.getServiceProxyResourceCustomization() == null
                || configuration.getServiceProxyResourceCustomization().getSourceService() == null
                || !configuration.getServiceProxyResourceCustomization().getSourceService().getServiceType()
                        .equalsIgnoreCase("TRANSPORT")) {
            throw new VrfBondingServiceException("Service: " + service.getModelName()
                    + " does not have a configuration of type VRF-ENTRY and role INFRASTRUCTURE-CLOUD-VPN"
                    + ", and serviceProxy that does not have source service that has a serviceType of TRANSPORT)");
        }
    }

    protected ConfigurationResourceCustomization getVrfConfiguration(org.onap.so.db.catalog.beans.Service service) {
        for (ConfigurationResourceCustomization configuration : service.getConfigurationCustomizations()) {
            if (configuration.getType() != null && configuration.getType().equalsIgnoreCase("VRF-ENTRY")
                    && configuration.getRole() != null
                    && configuration.getRole().equalsIgnoreCase("INFRASTRUCTURE-CLOUD-VPN")) {
                return configuration;
            }
        }
        return null;
    }

    protected void aaiVpnBindingValidation(String relatedVpnId, org.onap.aai.domain.yang.VpnBinding aaiVpnBinding)
            throws VrfBondingServiceException {
        if (aaiVpnBinding == null) {
            throw new VrfBondingServiceException("The infrastructure vpn " + relatedVpnId + " does not exist in A&AI.");
        } else if (aaiVpnBinding.getVpnType() != null
                && !aaiVpnBinding.getVpnType().equalsIgnoreCase("SERVICE-INFRASTRUCTURE")) {
            throw new VrfBondingServiceException(
                    "VpnBinding: " + relatedVpnId + " does not have a vpn type of SERVICE-INFRASTRUCTURE.");
        }
    }

    protected void aaiAggregateRouteValidation(org.onap.aai.domain.yang.L3Network aaiLocalNetwork)
            throws VrfBondingServiceException {
        if (aaiLocalNetwork.getAggregateRoutes() == null
                || aaiLocalNetwork.getAggregateRoutes().getAggregateRoute() == null) {
            return;
        }
        if (aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().size() == 1 && !aaiLocalNetwork
                .getAggregateRoutes().getAggregateRoute().get(0).getIpVersion().equalsIgnoreCase("4")) {
            throw new VrfBondingServiceException("LocalNetwork: " + aaiLocalNetwork.getNetworkId()
                    + " has 1 aggregate route but the Ip version of aggregate route is : "
                    + aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().get(0).getIpVersion() + " and is not 4");
        } else if (aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().size() == 2
                && !ipVersionValidation(aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().get(0).getIpVersion(),
                        aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().get(1).getIpVersion())) {
            throw new VrfBondingServiceException("LocalNetwork: " + aaiLocalNetwork.getNetworkId()
                    + " 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");
        } else if (aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().size() > 2) {
            throw new VrfBondingServiceException(
                    "LocalNetwork: " + aaiLocalNetwork.getNetworkId() + " either has more than 2 aggregate routes");
        }
    }

    protected void aaiNetworkValidation(String relatedNetworkid, org.onap.aai.domain.yang.L3Network aaiLocalNetwork)
            throws VrfBondingServiceException {
        if (aaiLocalNetwork == null) {
            throw new VrfBondingServiceException("The local network " + relatedNetworkid + " does not exist in A&AI.");
        }
    }

    protected void aaiSubnetValidation(org.onap.aai.domain.yang.L3Network aaiLocalNetwork)
            throws VrfBondingServiceException {
        if (aaiLocalNetwork.getSubnets() == null || aaiLocalNetwork.getSubnets().getSubnet() == null) {
            throw new VrfBondingServiceException("LocalNetwork: " + aaiLocalNetwork.getNetworkId() + " has no subnets");
        } else if (aaiLocalNetwork.getSubnets().getSubnet().size() == 1
                && !aaiLocalNetwork.getSubnets().getSubnet().get(0).getIpVersion().equalsIgnoreCase("4")) {
            throw new VrfBondingServiceException("LocalNetwork: " + aaiLocalNetwork.getNetworkId()
                    + " has 1 subnet but the Ip version of subnet is : "
                    + aaiLocalNetwork.getSubnets().getSubnet().get(0).getIpVersion() + " and is not 4");
        } else if (aaiLocalNetwork.getSubnets().getSubnet().size() == 2
                && !ipVersionValidation(aaiLocalNetwork.getSubnets().getSubnet().get(0).getIpVersion(),
                        aaiLocalNetwork.getSubnets().getSubnet().get(1).getIpVersion())) {
            throw new VrfBondingServiceException("LocalNetwork: " + aaiLocalNetwork.getNetworkId()
                    + " 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");
        } else if (aaiLocalNetwork.getSubnets().getSubnet().isEmpty()
                || aaiLocalNetwork.getSubnets().getSubnet().size() > 2) {
            throw new VrfBondingServiceException("LocalNetwork: " + aaiLocalNetwork.getNetworkId()
                    + " either has no subnets or more than 2 subnets");
        }
    }

    protected boolean ipVersionValidation(String ipVersion1, String ipVersion2) {
        return (ipVersion1.equalsIgnoreCase("4") && ipVersion2.equalsIgnoreCase("6"))
                || (ipVersion1.equalsIgnoreCase("6") && ipVersion2.equalsIgnoreCase("4"));
    }

    protected void aaiRouteTargetValidation(L3Network aaiLocalNetwork) throws VrfBondingServiceException {
        AAIResultWrapper networkWrapper = new AAIResultWrapper(aaiLocalNetwork);
        if (networkWrapper.getRelationships().isPresent()) {
            List<AAIResourceUri> vpnBindingUris =
                    networkWrapper.getRelationships().get().getRelatedUris(Types.VPN_BINDING);
            if (!vpnBindingUris.isEmpty()) {
                Optional<org.onap.aai.domain.yang.VpnBinding> vpnBindingOp =
                        bbInputSetupUtils.getAAIResourceDepthOne(vpnBindingUris.get(0))
                                .asBean(org.onap.aai.domain.yang.VpnBinding.class);
                if (vpnBindingOp.isPresent()) {
                    org.onap.aai.domain.yang.VpnBinding vpnBinding = vpnBindingOp.get();
                    if (vpnBinding.getRouteTargets() != null
                            && !vpnBinding.getRouteTargets().getRouteTarget().isEmpty()) {
                        return;
                    }
                }
            }
        }
        throw new VrfBondingServiceException("The Local Network: " + aaiLocalNetwork.getNetworkId()
                + " does not have vpn binding and/or RT information");
    }
}