[CCSDK-6] Populate seed code
[ccsdk/sli/adaptors.git] / resource-assignment / provider / src / main / java / org / openecomp / sdnc / util / vrf / VrfUtil.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 ONAP Intellectual Property. All rights
6  *                                              reserved.
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
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
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=========================================================
20  */
21
22 package org.openecomp.sdnc.util.vrf;
23
24 public class VrfUtil {
25
26         public static String createVrfInstanceName(
27                 String serviceInstanceId,
28                 String vpnId,
29                 String siteType,
30                 String routeGroup) {
31                 if (vpnId == null || vpnId.trim().length() == 0)
32                         return null;
33
34                 String ss = "VPN-" + vpnId;
35                 if (siteType != null && siteType.equalsIgnoreCase("hub"))
36                         ss += "-HUB";
37                 if (siteType != null && siteType.equalsIgnoreCase("spoke"))
38                         ss += "-SP-" + serviceInstanceId;
39                 if (routeGroup != null && routeGroup.trim().length() > 0)
40                         ss += "-RG-" + routeGroup;
41
42                 return ss;
43         }
44
45         public static VpnParam parseVrfInstanceName(String vrfInstanceName) {
46                 VpnParam vpnParam = new VpnParam();
47
48                 int i1 = vrfInstanceName.indexOf("-HUB");
49                 if (i1 > 0)
50                         vpnParam.siteType = "HUB";
51
52                 int i2 = vrfInstanceName.indexOf("-SP-");
53                 if (i2 > 0)
54                         vpnParam.siteType = "SPOKE";
55
56                 int i3 = vrfInstanceName.indexOf("-RG-");
57                 if (i3 > 0)
58                         vpnParam.routeGroupName = vrfInstanceName.substring(i3 + 4);
59
60                 int i4 = vrfInstanceName.length();
61                 if (i1 > 0)
62                         i4 = i1;
63                 else if (i2 > 0)
64                         i4 = i2;
65                 else if (i3 > 0)
66                         i4 = i3;
67                 vpnParam.vpnId = vrfInstanceName.substring(4, i4);
68
69                 if (i2 > 0 && i3 < 0)
70                         vpnParam.spokeServiceInstanceId = vrfInstanceName.substring(i2 + 4);
71                 if (i2 > 0 && i3 > 0)
72                         vpnParam.spokeServiceInstanceId = vrfInstanceName.substring(i2 + 4, i3);
73
74                 return vpnParam;
75         }
76 }