Fix bugs found in TN Slicing integration involving OOF
[so.git] / common / src / main / java / org / onap / so / beans / nsmf / SliceProfileAdapter.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2020 Huawei Technologies Co., Ltd. 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.so.beans.nsmf;
22
23 import com.fasterxml.jackson.annotation.JsonProperty;
24 import lombok.Data;
25 import lombok.ToString;
26 import org.springframework.beans.BeanUtils;
27 import java.io.Serializable;
28 import java.util.ArrayList;
29 import java.util.Arrays;
30 import java.util.List;
31
32 @Data
33 @ToString
34 public class SliceProfileAdapter implements Serializable {
35
36     private static final long serialVersionUID = -6412175980642584804L;
37
38     @JsonProperty(value = "sliceProfileId")
39     private String sliceProfileId;
40
41     @JsonProperty(value = "sNSSAI")
42     private String sNSSAIList = "";
43
44     @JsonProperty(value = "pLMNIdList")
45     private String pLMNIdList = "";
46
47     @JsonProperty(value = "maxNumberofUEs")
48     private int maxNumberOfUEs;
49
50     @JsonProperty(value = "coverageAreaTAList")
51     private String coverageAreaTAList = "";
52
53     @JsonProperty(value = "latency")
54     private int latency;
55
56     @JsonProperty(value = "uEMobilityLevel")
57     private String ueMobilityLevel;
58
59     @JsonProperty(value = "resourceSharingLevel")
60     private String resourceSharingLevel;
61
62     @JsonProperty(value = "maxBandwidth")
63     private int maxBandwidth;
64
65     @JsonProperty(value = "sST")
66     private String sST = "embb";
67
68     @JsonProperty(value = "activityFactor")
69     private int activityFactor;
70
71     @JsonProperty(value = "survivalTime")
72     private String survivalTime;
73
74     @JsonProperty(value = "expDataRateUL")
75     private int expDataRateUL;
76
77     @JsonProperty(value = "expDataRateDL")
78     private int expDataRateDL;
79
80     @JsonProperty(value = "areaTrafficCapUL")
81     private int areaTrafficCapUL;
82
83     @JsonProperty(value = "areaTrafficCapDL")
84     private int areaTrafficCapDL;
85
86     @JsonProperty(value = "jitter")
87     private int jitter;
88
89     @JsonProperty(value = "csAvailabilityTarget")
90     private float csAvailabilityTarget;
91
92     @JsonProperty(value = "expDataRate")
93     private int expDataRate;
94
95     @JsonProperty(value = "maxNumberofPDUSession")
96     private int maxNumberOfPDUSession;
97
98     @JsonProperty(value = "overallUserDensity")
99     private int overallUserDensity;
100
101     @JsonProperty(value = "cSReliabilityMeanTime")
102     private String csReliabilityMeanTime;
103
104     @JsonProperty(value = "msgSizeByte")
105     private String msgSizeByte;
106
107     @JsonProperty(value = "transferIntervalTarget")
108     private String transferIntervalTarget;
109
110     @JsonProperty(value = "ipAddress")
111     private String ipAddress;
112
113     @JsonProperty(value = "logicInterfaceId")
114     private String logicInterfaceId;
115
116     @JsonProperty(value = "nextHopInfo")
117     private String nextHopInfo;
118
119     public AnSliceProfile trans2AnProfile() {
120         AnSliceProfile anSliceProfile = new AnSliceProfile();
121         BeanUtils.copyProperties(this, anSliceProfile);
122         anSliceProfile.setSNSSAIList(Arrays.asList(this.sNSSAIList.split("\\|")));
123         anSliceProfile.setPLMNIdList(Arrays.asList(this.pLMNIdList.split("\\|")));
124
125         String[] areas = this.coverageAreaTAList.split("\\|");
126         Integer[] areasRes = new Integer[areas.length];
127         for (int i = 0; i < areas.length; i++) {
128             areasRes[i] = str2Code(areas[i]);
129         }
130         anSliceProfile.setCoverageAreaTAList(Arrays.asList(areasRes));
131
132         anSliceProfile.setUeMobilityLevel(UeMobilityLevel.fromString(this.ueMobilityLevel));
133         anSliceProfile.setResourceSharingLevel(ResourceSharingLevel.fromString(this.resourceSharingLevel));
134         anSliceProfile.setMaxNumberOfPDUSession(this.maxNumberOfPDUSession);
135         anSliceProfile.setPerfReq(generatePerfReq());
136
137         return anSliceProfile;
138     }
139
140     private Integer str2Code(String area) {
141         return area.hashCode() >> 16;
142     }
143
144     public CnSliceProfile trans2CnProfile() {
145         CnSliceProfile cnSliceProfile = new CnSliceProfile();
146         BeanUtils.copyProperties(this, cnSliceProfile);
147         cnSliceProfile.setSnssaiList(Arrays.asList(this.sNSSAIList.split("\\|")));
148         cnSliceProfile.setCoverageAreaTAList(Arrays.asList(this.coverageAreaTAList.split("\\|")));
149         cnSliceProfile.setPLMNIdList(Arrays.asList(this.pLMNIdList.split("\\|")));
150         cnSliceProfile.setResourceSharingLevel(ResourceSharingLevel.fromString(this.resourceSharingLevel));
151
152         cnSliceProfile.setPerfReq(generatePerfReq());
153         return cnSliceProfile;
154     }
155
156     private PerfReq generatePerfReq() {
157         PerfReq perfReq = new PerfReq();
158         if ("embb".equalsIgnoreCase(sST)) {
159             List<PerfReqEmbb> perfReqEmbbs = new ArrayList<>();
160             PerfReqEmbb perfReqEmbb = new PerfReqEmbb();
161             BeanUtils.copyProperties(this, perfReqEmbb);
162             perfReqEmbbs.add(perfReqEmbb);
163             perfReq.setPerfReqEmbbList(perfReqEmbbs);
164         } else if ("urllc".equalsIgnoreCase(sST)) {
165             List<PerfReqUrllc> perfReqUrllcs = new ArrayList<>();
166             PerfReqUrllc perfReqUrllc = new PerfReqUrllc();
167             BeanUtils.copyProperties(this, perfReqUrllc);
168             perfReqUrllcs.add(perfReqUrllc);
169             perfReq.setPerfReqUrllcList(perfReqUrllcs);
170         }
171         return perfReq;
172     }
173
174     public TnSliceProfile trans2TnProfile() {
175         TnSliceProfile tnSliceProfile = new TnSliceProfile();
176         BeanUtils.copyProperties(this, tnSliceProfile);
177         tnSliceProfile.setSNSSAIList(Arrays.asList(this.sNSSAIList.split("\\|")));
178         tnSliceProfile.setPLMNIdList(Arrays.asList(this.pLMNIdList.split("\\|")));
179         tnSliceProfile.setResourceSharingLevel(ResourceSharingLevel.fromString(this.resourceSharingLevel));
180         return tnSliceProfile;
181     }
182 }