diff options
Diffstat (limited to 'src')
46 files changed, 3360 insertions, 0 deletions
diff --git a/src/main/java/com/cmcc/simulator/SimulatorApplication.java b/src/main/java/com/cmcc/simulator/SimulatorApplication.java new file mode 100644 index 0000000..ed5681b --- /dev/null +++ b/src/main/java/com/cmcc/simulator/SimulatorApplication.java @@ -0,0 +1,21 @@ +package com.cmcc.simulator; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.web.client.RestTemplate; + +@SpringBootApplication +public class SimulatorApplication { + + public static void main(String[] args) { + SpringApplication.run(SimulatorApplication.class, args); + } + + @Bean + public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder){ + return restTemplateBuilder.build(); + } + +} diff --git a/src/main/java/com/cmcc/simulator/authmodule/AuthRequest.java b/src/main/java/com/cmcc/simulator/authmodule/AuthRequest.java new file mode 100644 index 0000000..f481d25 --- /dev/null +++ b/src/main/java/com/cmcc/simulator/authmodule/AuthRequest.java @@ -0,0 +1,51 @@ +package com.cmcc.simulator.authmodule; + +/* + * "grantType": "password", + "userName": "test", +"value": "XXXXXX" + + * */ +public class AuthRequest { + + private String grantType; + private String userName; + private String value; + + public AuthRequest() { + super(); + // TODO Auto-generated constructor stub + } + + public AuthRequest(String grantType, String userName, String value) { + super(); + this.grantType = grantType; + this.userName = userName; + this.value = value; + } + + public String getGrantType() { + return grantType; + } + + public void setGrantType(String grantType) { + this.grantType = grantType; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + +} diff --git a/src/main/java/com/cmcc/simulator/authmodule/AuthResponse.java b/src/main/java/com/cmcc/simulator/authmodule/AuthResponse.java new file mode 100644 index 0000000..6a43904 --- /dev/null +++ b/src/main/java/com/cmcc/simulator/authmodule/AuthResponse.java @@ -0,0 +1,41 @@ +package com.cmcc.simulator.authmodule; + +/* + * “accessToken”:”7512eb3feb5249eca5ddd742fedddd39”, +“expires”:1800 + + * */ + +public class AuthResponse { + + private String accessToken; + private int expires; + + public AuthResponse() { + super(); + // TODO Auto-generated constructor stub + } + + public AuthResponse(String accessToken, int expires) { + super(); + this.accessToken = accessToken; + this.expires = expires; + } + + public String getAccessToken() { + return accessToken; + } + + public void setAccessToken(String accessToken) { + this.accessToken = accessToken; + } + + public int getExpires() { + return expires; + } + + public void setExpires(int expires) { + this.expires = expires; + } + +} diff --git a/src/main/java/com/cmcc/simulator/controller/AuthenticationController.java b/src/main/java/com/cmcc/simulator/controller/AuthenticationController.java new file mode 100644 index 0000000..0eb0b9b --- /dev/null +++ b/src/main/java/com/cmcc/simulator/controller/AuthenticationController.java @@ -0,0 +1,25 @@ +package com.cmcc.simulator.controller; + +import java.util.UUID; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +import com.cmcc.simulator.authmodule.AuthRequest; +import com.cmcc.simulator.authmodule.AuthResponse; + +@RestController +@RequestMapping("/api/rest/securityManagement/v1") +public class AuthenticationController { + + @PostMapping("/oauth/token") + @ResponseStatus(HttpStatus.OK) + public AuthResponse nSSIChangeNotify(@RequestBody AuthRequest nSSIChangeNotify) { + return new AuthResponse(UUID.randomUUID().toString().replaceAll("-",""), 1800); + } + +} diff --git a/src/main/java/com/cmcc/simulator/controller/SliceController.java b/src/main/java/com/cmcc/simulator/controller/SliceController.java new file mode 100644 index 0000000..ede80a4 --- /dev/null +++ b/src/main/java/com/cmcc/simulator/controller/SliceController.java @@ -0,0 +1,581 @@ +package com.cmcc.simulator.controller; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +import com.alibaba.fastjson.JSONObject; +import com.cmcc.simulator.module.Extension; +import com.cmcc.simulator.module.JobInfo; +import com.cmcc.simulator.module.JobResponse; +import com.cmcc.simulator.module.NSSIChangeNotify; +import com.cmcc.simulator.module.NestedNsInstance; +import com.cmcc.simulator.module.NestedVnfInstance; +import com.cmcc.simulator.module.NetworkSliceSubnet; +import com.cmcc.simulator.module.NsInstanceInfo; +import com.cmcc.simulator.module.Nssi; +import com.cmcc.simulator.module.NssiInfo; +import com.cmcc.simulator.module.NssiResponse; +import com.cmcc.simulator.module.PerfReq; +import com.cmcc.simulator.module.PerfReqEmbb; +import com.cmcc.simulator.module.PnfInfo; +import com.cmcc.simulator.module.ResponseDescriptor; +import com.cmcc.simulator.module.ResponseHistory; +import com.cmcc.simulator.module.SliceProfile; +import com.cmcc.simulator.module.VnfInstance; +import com.cmcc.simulator.service.SimulatorService; +import com.cmcc.simulator.util.StringUtil; + +@RestController +@RequestMapping("/api/rest/provMns/v1") +public class SliceController { + + private static final Logger logger = LoggerFactory.getLogger(SliceController.class); + + @Autowired + private SimulatorService service; + + @GetMapping("/NSS/nssi/{id}") + public ResponseEntity<NssiInfo> getNSSIbyId(@PathVariable String id) { + if (!service.getNssiIds().contains(id)) { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + NssiInfo nssiInfo = new NssiInfo(); + Nssi nssi = new Nssi(); + nssi.setNssiId("NSSI-C-001-HDBNJ-NSSMF-01-A-ZX"); + nssi.setNssiName("test_CN"); + nssi.setNsstId("NSST-C-001-HDBNJ-NSSMF-01-A-ZX"); + nssi.setFlavorId("ab9af40f13f721b5f "); + nssi.setNssiState("enabled"); + + NetworkSliceSubnet networkSliceSubnet = new NetworkSliceSubnet(); + + String[] mfIdList = { "1301ZTHX2SMFA12ZA1", "1301ZTHX2UPF023A4D", "1301ZTHX2SMF723ADF" }; + NsInstanceInfo nsInfo = new NsInstanceInfo(); + List<SliceProfile> sliceProfileList = new ArrayList<>(); + + nsInfo.setNsInstanceId("fe9af40f13f721b5f13539d87488899"); + nsInfo.setNsInstanceName("test_NS"); + nsInfo.setNsdId("7356240f13f721b5f13539d87ad2341"); + nsInfo.setNsState("nsState"); + + List<VnfInstance> vnfInstanceList = new ArrayList<>(); + List<PnfInfo> pnfInfoList = new ArrayList<>(); + List<NestedNsInstance> nestedNsInstanceList = new ArrayList<>(); + + VnfInstance vnfInstance = new VnfInstance("2345640f13f721b5f13539d8748ade4", "smf", + "a345640f13f721b5f13539d8748adef", "active"); + vnfInstanceList.add(vnfInstance); + + PnfInfo pnfInfo = new PnfInfo("8aed640f13f721b5f13539d874812a8", "upf", "ffff640f13f721b5f13539d87482222"); + pnfInfoList.add(pnfInfo); + + NestedNsInstance nestedNsInstance = new NestedNsInstance(); + String[] nestedNsInstanceId = { "bbbcf40f13f721b5f13539d8748aedd" }; + nestedNsInstance.setNsInstanceId("1233f40f13f721b5f13539d87488333"); + nestedNsInstance.setNsInstanceName("nested_ns"); + nestedNsInstance.setNsdId("abc6240f13f721b5f13539d87ad2abc"); + nestedNsInstance.setNestedNsInstanceId(nestedNsInstanceId); + nestedNsInstance.setNsState("active"); + + NestedVnfInstance nestedVnfInstance = new NestedVnfInstance(); + nestedVnfInstance.setVnfInstanceId("amf"); + nestedVnfInstance.setVnfInstanceName("amf"); + nestedVnfInstance.setVnfdId("8885640f13f721b5f13539d8748adef"); + nestedVnfInstance.setInstantiationState("active"); + + List<NestedVnfInstance> nestedVnfInstanceList = new ArrayList<>(); + nestedVnfInstanceList.add(nestedVnfInstance); + nestedNsInstance.setNestedVnfInstanceList(nestedVnfInstanceList); + + nestedNsInstanceList.add(nestedNsInstance); + + nsInfo.setPnfInfo(pnfInfoList); + nsInfo.setVnfInstance(vnfInstanceList); + nsInfo.setNestedNsInstance(nestedNsInstanceList); + + SliceProfile sliceProfile = new SliceProfile(); + sliceProfile.setSliceProfileId("ab9af40f13f721b5f13539d87484098"); + + int size = service.getSnssaiIds().size(); + String[] snssaiList = (String[]) service.getSnssaiIds().toArray(new String[size]); + sliceProfile.setSnssaiList(snssaiList); + + String[] plmnIdList = { "460-00" }; + sliceProfile.setPlmnIdList(plmnIdList); + + PerfReq perfReq = new PerfReq(); + List<PerfReqEmbb> perfReqEmbbList = new ArrayList<>(); + PerfReqEmbb perfReqEmbb = new PerfReqEmbb(); + perfReqEmbb.setActivityFactor(50); + perfReqEmbbList.add(perfReqEmbb); + perfReq.setPerfReqEmbbList(perfReqEmbbList); + + sliceProfile.setPerfReq(perfReq); + sliceProfile.setMaxNumberofUEs(200); + sliceProfileList.add(sliceProfile); + String[] coverageAreaTAList = { "1", "2", "3", "4" }; + sliceProfile.setCoverageAreaTAList(coverageAreaTAList); + sliceProfile.setLatency(2); + sliceProfile.setResourceSharingLevel("non-shared"); + + networkSliceSubnet.setMfIdList(mfIdList); + networkSliceSubnet.setNsInfo(nsInfo); + networkSliceSubnet.setSliceProfileList(sliceProfileList); + + nssi.setNetworkSliceSubnet(networkSliceSubnet); + + nssiInfo.setNssiInfo(nssi); + + return new ResponseEntity<>(nssiInfo, HttpStatus.OK); + } + + @GetMapping("/NSS/SliceProfiles/{id}") + public ResponseEntity<NssiInfo> getNSSI(@PathVariable String id) { + if (!service.getSliceProfileIds().contains(id)) { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + NssiInfo nssiInfo = new NssiInfo(); + Nssi nssi = new Nssi(); + nssi.setNssiId("NSSI-C-001-HDBNJ-NSSMF-01-A-ZX"); + nssi.setNssiName("test_CN"); + nssi.setNsstId("NSST-C-001-HDBNJ-NSSMF-01-A-ZX"); + nssi.setFlavorId("ab9af40f13f721b5f "); + nssi.setNssiState("enabled"); + + NetworkSliceSubnet networkSliceSubnet = new NetworkSliceSubnet(); + + String[] mfIdList = { "1301ZTHX2SMFA12ZA1", "1301ZTHX2UPF023A4D", "1301ZTHX2SMF723ADF" }; + NsInstanceInfo nsInfo = new NsInstanceInfo(); + List<SliceProfile> sliceProfileList = new ArrayList<>(); + + nsInfo.setNsInstanceId("fe9af40f13f721b5f13539d87488899"); + nsInfo.setNsInstanceName("test_NS"); + nsInfo.setNsdId("7356240f13f721b5f13539d87ad2341"); + nsInfo.setNsState("nsState"); + + List<VnfInstance> vnfInstanceList = new ArrayList<>(); + List<PnfInfo> pnfInfoList = new ArrayList<>(); + List<NestedNsInstance> nestedNsInstanceList = new ArrayList<>(); + + VnfInstance vnfInstance = new VnfInstance("2345640f13f721b5f13539d8748ade4", "smf", + "a345640f13f721b5f13539d8748adef", "active"); + vnfInstanceList.add(vnfInstance); + + PnfInfo pnfInfo = new PnfInfo("8aed640f13f721b5f13539d874812a8", "upf", "ffff640f13f721b5f13539d87482222"); + pnfInfoList.add(pnfInfo); + + NestedNsInstance nestedNsInstance = new NestedNsInstance(); + String[] nestedNsInstanceId = { "bbbcf40f13f721b5f13539d8748aedd" }; + nestedNsInstance.setNsInstanceId("1233f40f13f721b5f13539d87488333"); + nestedNsInstance.setNsInstanceName("nested_ns"); + nestedNsInstance.setNsdId("abc6240f13f721b5f13539d87ad2abc"); + nestedNsInstance.setNestedNsInstanceId(nestedNsInstanceId); + nestedNsInstance.setNsState("active"); + + NestedVnfInstance nestedVnfInstance = new NestedVnfInstance(); + nestedVnfInstance.setVnfInstanceId("amf"); + nestedVnfInstance.setVnfInstanceName("amf"); + nestedVnfInstance.setVnfdId("8885640f13f721b5f13539d8748adef"); + nestedVnfInstance.setInstantiationState("active"); + + List<NestedVnfInstance> nestedVnfInstanceList = new ArrayList<>(); + nestedVnfInstanceList.add(nestedVnfInstance); + nestedNsInstance.setNestedVnfInstanceList(nestedVnfInstanceList); + + nestedNsInstanceList.add(nestedNsInstance); + + nsInfo.setPnfInfo(pnfInfoList); + nsInfo.setVnfInstance(vnfInstanceList); + nsInfo.setNestedNsInstance(nestedNsInstanceList); + + SliceProfile sliceProfile = new SliceProfile(); + sliceProfile.setSliceProfileId("ab9af40f13f721b5f13539d87484098"); + + int size = service.getSnssaiIds().size(); + String[] snssaiList = (String[]) service.getSnssaiIds().toArray(new String[size]); + sliceProfile.setSnssaiList(snssaiList); + + String[] plmnIdList = { "460-00" }; + sliceProfile.setPlmnIdList(plmnIdList); + + PerfReq perfReq = new PerfReq(); + List<PerfReqEmbb> perfReqEmbbList = new ArrayList<>(); + PerfReqEmbb perfReqEmbb = new PerfReqEmbb(); + perfReqEmbb.setActivityFactor(50); + perfReqEmbbList.add(perfReqEmbb); + perfReq.setPerfReqEmbbList(perfReqEmbbList); + + sliceProfile.setPerfReq(perfReq); + sliceProfile.setMaxNumberofUEs(200); + + String[] coverageAreaTAList = { "1", "2", "3", "4" }; + sliceProfile.setCoverageAreaTAList(coverageAreaTAList); + sliceProfile.setLatency(2); + sliceProfile.setResourceSharingLevel("non-shared"); + sliceProfileList.add(sliceProfile); + networkSliceSubnet.setMfIdList(mfIdList); + networkSliceSubnet.setNsInfo(nsInfo); + networkSliceSubnet.setSliceProfileList(sliceProfileList); + + nssi.setNetworkSliceSubnet(networkSliceSubnet); +// List<SliceProfile> sliceProfileList2 = new ArrayList<>(); +// sliceProfileList.add(sliceProfile); +// nssi.setSliceProfileList(sliceProfileList2); + nssiInfo.setNssiInfo(nssi); + return new ResponseEntity<>(nssiInfo, HttpStatus.OK); + } + + @DeleteMapping("/NSS/nssi/{nssiId}") + public ResponseEntity<JobResponse> terminateNSSI(@PathVariable String nssiId, @RequestBody Nssi nssi) { + + logger.info("terminateNSSI: nssiid: {}, NSSI: {}", nssiId, JSONObject.toJSON(nssi).toString()); + if (service.getNssiIds().contains(nssiId)) { + JobResponse res = new JobResponse(); + String jobId = UUID.randomUUID().toString().replaceAll("-", ""); + res.setJobId(jobId); + service.removeNssiIds(nssiId); + service.addJobIds(jobId); + return new ResponseEntity<>(res, HttpStatus.ACCEPTED); + } else { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + } + + @DeleteMapping("/NSS/SliceProfiles/{sliceProfileId}") + public ResponseEntity<JobResponse> deallocateNSSI(@PathVariable String sliceProfileId, + @RequestBody SliceProfile sliceProfile) { + + logger.info("deallocateNSSI: sliceProfileId: {}, sliceProfile: {}", sliceProfileId, + JSONObject.toJSON(sliceProfile).toString()); + if (!service.getSliceProfileIds().contains(sliceProfileId)) { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + String nssiId = sliceProfile.getNssiId(); + if (service.getNssiIds().contains(nssiId)) { + JobResponse res = new JobResponse(); + String jobId = UUID.randomUUID().toString().replaceAll("-", ""); + res.setJobId(jobId); + service.removeNssiIds(nssiId); + service.removeSliceProfileIds(sliceProfileId); + service.addJobIds(jobId); + String[] snssaiList = sliceProfile.getSnssaiList(); + Arrays.asList(snssaiList).stream().forEach(snssai -> { + service.removeSnssaiIds(snssai); + service.removeActivatedSlices(snssai);; + }); + logger.info("deallocateNSSI response: {}", JSONObject.toJSON(res).toString()); + + return new ResponseEntity<>(res, HttpStatus.ACCEPTED); + } else { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + } + + @PostMapping("/NSS/SliceProfiles") + @ResponseStatus(HttpStatus.ACCEPTED) + public NssiResponse allocateNSSI(@RequestBody Nssi nssi) { + + logger.info("allocateNSSI: Nssi: {}", JSONObject.toJSON(nssi).toString()); + + String[] snssaiList = nssi.getSliceProfile().getSnssaiList(); + Arrays.asList(snssaiList).stream().forEach(snssai -> { + service.addSnssaiIds(snssai); + }); + +// String nssiId = "NSSI-C-001-HDBNJ-NSSMF-01-A-ZX"; + String nssiId = nssi.getNssiId(); + if (nssiId == null) { + nssiId = "NSSI-C-" + StringUtil.randomStr(3) + "-HDBNJ-NSSMF-01-A-ZX"; + } + String jobId = UUID.randomUUID().toString().replaceAll("-", ""); + NssiResponse res = new NssiResponse(); + res.setNssiId(nssiId); + res.setJobId(jobId); + + service.addNssiIds(nssiId); + service.addJobIds(jobId); + service.addSliceProfileIds(nssi.getSliceProfile().getSliceProfileId()); + service.addNsstIds(nssi.getNsstId()); + + logger.info("allocateNSSI response: {}", JSONObject.toJSON(res).toString()); + + return res; + } + + @PostMapping("/NSS/nssi/notification") + @ResponseStatus(HttpStatus.CREATED) + public Extension nSSIChangeNotify(@RequestBody NSSIChangeNotify nSSIChangeNotify) { + logger.info("nSSIChangeNotify: {}", nSSIChangeNotify); + return new Extension(); + } + + @PutMapping("/NSS/SliceProfiles/{sliceProfileId}") + public ResponseEntity<JobResponse> modifyNSSI(@PathVariable String sliceProfileId, @RequestBody Nssi nssi) { + + logger.info("modifyNSSI: sliceProfileId: {}, Nssi {}", sliceProfileId, JSONObject.toJSON(nssi).toString()); + + if (!service.getSliceProfileIds().contains(sliceProfileId)) { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + if (!service.getNssiIds().contains(nssi.getNssiId())) { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + + if (!service.getNsstIds().contains(nssi.getNsstId())) { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + + String jobId; + JobResponse res = new JobResponse(); + if (nssi.getJobId() != null) { + jobId = nssi.getJobId(); + res.setJobId(jobId); + } else { + jobId = UUID.randomUUID().toString().replaceAll("-", ""); + res.setJobId(jobId); + } + service.addJobIds(jobId); + + return new ResponseEntity<>(res, HttpStatus.ACCEPTED); + } + + @PutMapping("/NSS/nssi/{nssiId}") + public ResponseEntity<JobResponse> modifyNSSIbyId(@PathVariable String nssiId, @RequestBody Nssi nssi) { + + logger.info("modifyNSSIbyId: nssiId: {}, Nssi {}", nssiId, JSONObject.toJSON(nssi).toString()); + + if (!service.getNssiIds().contains(nssiId)) { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + + if (!service.getNsstIds().contains(nssi.getNsstId())) { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + + String jobId; + JobResponse res = new JobResponse(); + if (nssi.getJobId() != null) { + jobId = nssi.getJobId(); + res.setJobId(jobId); + } else { + jobId = UUID.randomUUID().toString().replaceAll("-", ""); + res.setJobId(jobId); + } + service.addJobIds(jobId); + return new ResponseEntity<>(res, HttpStatus.ACCEPTED); + } + + @PutMapping("/NSS/{snssai}/activation") + public ResponseEntity<JobResponse> activateNSSI(@PathVariable String snssai, @RequestBody Nssi nssi) { + logger.info("activateNSSI: snssai: {}, Nssi {}", snssai, JSONObject.toJSON(nssi).toString()); + + if (!service.getSnssaiIds().contains(snssai)) { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + + if (!service.getNssiIds().contains(nssi.getNssiId())) { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + + String jobId; + JobResponse res = new JobResponse(); + if (nssi.getJobId() != null) { + jobId = nssi.getJobId(); + res.setJobId(jobId); + } else { + jobId = UUID.randomUUID().toString().replaceAll("-", ""); + res.setJobId(jobId); + } + service.addJobIds(jobId); + service.addActivatedSlices(snssai); + logger.info("activateNSSI response: {}", JSONObject.toJSON(res).toString()); + + return new ResponseEntity<>(res, HttpStatus.ACCEPTED); + } + + @PutMapping("/NSS/{snssai}/deactivation") + public ResponseEntity<JobResponse> deactivateNSSI(@PathVariable String snssai, @RequestBody Nssi nssi) { + + logger.info("deactivateNSSI: snssai: {}, Nssi {}", snssai, JSONObject.toJSON(nssi).toString()); + if (!service.getSnssaiIds().contains(snssai)) { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + + if (!service.getNssiIds().contains(nssi.getNssiId())) { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + + String jobId; + JobResponse res = new JobResponse(); + if (nssi.getJobId() != null) { + jobId = nssi.getJobId(); + res.setJobId(jobId); + } else { + jobId = UUID.randomUUID().toString().replaceAll("-", ""); + res.setJobId(jobId); + } + service.addJobIds(jobId); + service.removeActivatedSlices(snssai); + logger.info("deactivateNSSI response: {}", JSONObject.toJSON(res).toString()); + + return new ResponseEntity<>(res, HttpStatus.ACCEPTED); + } + + @GetMapping("/NSS/jobs/{jobId}") +// public ResponseEntity<JobInfo> getJobStatus(@PathVariable String jobId, @RequestParam("responseId") String responseId) { + public ResponseEntity<JobInfo> getJobStatus(@PathVariable String jobId) { + +// logger.info("get job status: jobid:{}, responseid:{}", jobId, responseId); + logger.info("get job status: jobid:{}", jobId); + + if (!service.getJobIds().contains(jobId)) { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + + ResponseDescriptor responseDescriptor = new ResponseDescriptor(); + Map<String, Integer> jobCheckCountMap = service.getJobCheckCount(); + if (jobCheckCountMap.get(jobId) == null) { + service.updateJobCheckCount(jobId, 1); + responseDescriptor.setProgress(20); + responseDescriptor.setStatus("processing"); + responseDescriptor.setStatusDescription("Initiating VNF Instance"); + responseDescriptor.setResponseId("1"); + + } else { + List<ResponseHistory> responseHistoryList = new ArrayList<>(); + if (jobCheckCountMap.get(jobId) == 1) { + service.updateJobCheckCount(jobId, 2); + responseDescriptor.setProgress(40); + responseDescriptor.setStatus("processing"); + responseDescriptor.setStatusDescription("Preparing for Instantiating NSSI"); + responseDescriptor.setResponseId("2"); + + ResponseHistory responseHistory1 = new ResponseHistory(); + responseHistory1.setProgress(20); + responseHistory1.setStatus("processing"); + responseHistory1.setStatusDescription("Initiating VNF Instance"); + responseHistory1.setResponseId("1"); + + responseHistoryList.add(responseHistory1); + } + + else if (jobCheckCountMap.get(jobId) == 2) { + service.updateJobCheckCount(jobId, 3); + responseDescriptor.setProgress(75); + responseDescriptor.setStatus("processing"); + responseDescriptor.setStatusDescription("Check Requirements of NSSI"); + responseDescriptor.setResponseId("3"); + + ResponseHistory responseHistory1 = new ResponseHistory(); + responseHistory1.setProgress(20); + responseHistory1.setStatus("processing"); + responseHistory1.setStatusDescription("Initiating VNF Instance"); + responseHistory1.setResponseId("1"); + + ResponseHistory responseHistory2 = new ResponseHistory(); + responseHistory2.setProgress(40); + responseHistory2.setStatus("processing"); + responseHistory2.setStatusDescription("Preparing for Instantiating NSSI"); + responseHistory2.setResponseId("2"); + + responseHistoryList.add(responseHistory1); + responseHistoryList.add(responseHistory2); + } + + else if (jobCheckCountMap.get(jobId) == 3) { + service.updateJobCheckCount(jobId, 4); + responseDescriptor.setProgress(100); + responseDescriptor.setStatus("finished"); + responseDescriptor.setStatusDescription("Complete Successfully"); + responseDescriptor.setResponseId("4"); + + ResponseHistory responseHistory1 = new ResponseHistory(); + responseHistory1.setProgress(20); + responseHistory1.setStatus("processing"); + responseHistory1.setStatusDescription("Initiating VNF Instance"); + responseHistory1.setResponseId("1"); + + ResponseHistory responseHistory2 = new ResponseHistory(); + responseHistory2.setProgress(40); + responseHistory2.setStatus("processing"); + responseHistory2.setStatusDescription("Preparing for Instantiating NSSI"); + responseHistory2.setResponseId("2"); + + ResponseHistory responseHistory3 = new ResponseHistory(); + responseHistory2.setProgress(75); + responseHistory2.setStatus("processing"); + responseHistory2.setStatusDescription("Check Requirements of NSSI"); + responseHistory2.setResponseId("3"); + + responseHistoryList.add(responseHistory1); + responseHistoryList.add(responseHistory2); + responseHistoryList.add(responseHistory3); + } + responseDescriptor.setResponseHistoryList(responseHistoryList); + } + + JobInfo jobInfo = new JobInfo(); + jobInfo.setResponseDescriptor(responseDescriptor); + return new ResponseEntity<>(jobInfo, HttpStatus.OK); + + } + + @GetMapping("/jobs") + public List<String> getJobStatus() { + return service.getJobIds(); + } + + @GetMapping("/snssaiIds") + public List<String> getSnssaiIds() { + return service.getSnssaiIds(); + } + + @GetMapping("/nssiIds") + public List<String> getNssiIds() { + return service.getNssiIds(); + } + + @GetMapping("/sliceProfileIds") + public List<String> getSliceProfileIds() { + return service.getSliceProfileIds(); + } + + @GetMapping("/nsstIds") + public List<String> getNsstIds() { + return service.getNsstIds(); + } + + @GetMapping("/activatedSlices") + public List<String> getActivatedSlices() { + return service.getActivatedSlices(); + } + + @GetMapping("/createPM") + public void createPM() throws Exception { + List<String> nsstIds = new ArrayList<>(); + nsstIds.add("01-12345678"); + nsstIds.add("01-23456789"); + service.createAMF(nsstIds); + service.createUPF(nsstIds); + service.gzipFiles(); + } + +}
\ No newline at end of file diff --git a/src/main/java/com/cmcc/simulator/job/ScheduleJob.java b/src/main/java/com/cmcc/simulator/job/ScheduleJob.java new file mode 100644 index 0000000..0a91750 --- /dev/null +++ b/src/main/java/com/cmcc/simulator/job/ScheduleJob.java @@ -0,0 +1,55 @@ +package com.cmcc.simulator.job; + +import java.util.ArrayList; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import com.alibaba.fastjson.JSONObject; +import com.cmcc.simulator.service.SimulatorService; +import com.cmcc.simulator.xml.FileReadyEvent; +import com.cmcc.simulator.xml.Utils; + +@Component +@EnableScheduling +public class ScheduleJob { + + private static final Logger logger = LoggerFactory.getLogger(ScheduleJob.class); + @Autowired + private SimulatorService service; + + @Value("${ftppath}") + private String ftpPath; + + @Scheduled(fixedDelayString = "${fixeddelay}") + public void runThird() throws Exception { + List<String> nsstIds = service.getActivatedSlices(); + if (!nsstIds.isEmpty()) { + logger.info("the snssai list is : {}", nsstIds); + service.createAMF(nsstIds); + service.createUPF(nsstIds); + service.gzipFiles(); + + List<String> list = new ArrayList<String>(); + list.add(ftpPath); + + FileReadyEvent event = new FileReadyEvent(); + event.setCreateat(Utils.getTimeFormat()); + event.setDatasource("VIM"); + event.setFileuri(list); + event.setNfvoid("10.10.10.1"); + event.setSourceid("10011001"); + + service.notify(event); + service.delFiles(); + logger.info("notify pm data success: {}", JSONObject.toJSON(event).toString()); + } + } + +} diff --git a/src/main/java/com/cmcc/simulator/module/Extension.java b/src/main/java/com/cmcc/simulator/module/Extension.java new file mode 100644 index 0000000..7fff14e --- /dev/null +++ b/src/main/java/com/cmcc/simulator/module/Extension.java @@ -0,0 +1,24 @@ +package com.cmcc.simulator.module; + +public class Extension { + + private String extension; + + public Extension() { + super(); + } + + public Extension(String extension) { + super(); + this.extension = extension; + } + + public String getExtension() { + return extension; + } + + public void setExtension(String extension) { + this.extension = extension; + } + +} diff --git a/src/main/java/com/cmcc/simulator/module/JobInfo.java b/src/main/java/com/cmcc/simulator/module/JobInfo.java new file mode 100644 index 0000000..156a6cd --- /dev/null +++ b/src/main/java/com/cmcc/simulator/module/JobInfo.java @@ -0,0 +1,24 @@ +package com.cmcc.simulator.module; + +public class JobInfo { + private ResponseDescriptor responseDescriptor; + + public JobInfo() { + super(); + // TODO Auto-generated constructor stub + } + + public JobInfo(ResponseDescriptor responseDescriptor) { + super(); + this.responseDescriptor = responseDescriptor; + } + + public ResponseDescriptor getResponseDescriptor() { + return responseDescriptor; + } + + public void setResponseDescriptor(ResponseDescriptor responseDescriptor) { + this.responseDescriptor = responseDescriptor; + } + +} diff --git a/src/main/java/com/cmcc/simulator/module/JobResponse.java b/src/main/java/com/cmcc/simulator/module/JobResponse.java new file mode 100644 index 0000000..ddaad78 --- /dev/null +++ b/src/main/java/com/cmcc/simulator/module/JobResponse.java @@ -0,0 +1,26 @@ +package com.cmcc.simulator.module; + +public class JobResponse { + + private String jobId; + + public JobResponse() { + super(); + // TODO Auto-generated constructor stub + } + + public JobResponse(String jobId) { + super(); + this.jobId = jobId; + } + + public String getJobId() { + return jobId; + } + + public void setJobId(String jobId) { + this.jobId = jobId; + } + + +} diff --git a/src/main/java/com/cmcc/simulator/module/NSSIChangeNotify.java b/src/main/java/com/cmcc/simulator/module/NSSIChangeNotify.java new file mode 100644 index 0000000..c3335b6 --- /dev/null +++ b/src/main/java/com/cmcc/simulator/module/NSSIChangeNotify.java @@ -0,0 +1,25 @@ +package com.cmcc.simulator.module; + +public class NSSIChangeNotify { + + private String[] changedNssiList; + + public NSSIChangeNotify() { + super(); + // TODO Auto-generated constructor stub + } + + public NSSIChangeNotify(String[] changedNssiList) { + super(); + this.changedNssiList = changedNssiList; + } + + public String[] getChangedNssiList() { + return changedNssiList; + } + + public void setChangedNssiList(String[] changedNssiList) { + this.changedNssiList = changedNssiList; + } + +} diff --git a/src/main/java/com/cmcc/simulator/module/NestedNsInstance.java b/src/main/java/com/cmcc/simulator/module/NestedNsInstance.java new file mode 100644 index 0000000..49da26c --- /dev/null +++ b/src/main/java/com/cmcc/simulator/module/NestedNsInstance.java @@ -0,0 +1,99 @@ +package com.cmcc.simulator.module; + +import java.util.List; + +public class NestedNsInstance { + + private String nsInstanceId; + private String nsInstanceName; + private String nsInstanceDescription; + private String nsdId; + private List<NestedVnfInstance> nestedVnfInstanceList; + private List<NestedPnfInfo> nestedPnfInfoList; + private String[] nestedNsInstanceId; + private String nsState; + + public NestedNsInstance() { + super(); + // TODO Auto-generated constructor stub + } + + public NestedNsInstance(String nsInstanceId, String nsInstanceName, String nsInstanceDescription, String nsdId, + List<NestedVnfInstance> nestedVnfInstanceList, List<NestedPnfInfo> nestedPnfInfoList, String[] nestedNsInstanceId, + String nsState) { + super(); + this.nsInstanceId = nsInstanceId; + this.nsInstanceName = nsInstanceName; + this.nsInstanceDescription = nsInstanceDescription; + this.nsdId = nsdId; + this.nestedVnfInstanceList = nestedVnfInstanceList; + this.nestedPnfInfoList = nestedPnfInfoList; + this.nestedNsInstanceId = nestedNsInstanceId; + this.nsState = nsState; + } + + public String getNsInstanceId() { + return nsInstanceId; + } + + public void setNsInstanceId(String nsInstanceId) { + this.nsInstanceId = nsInstanceId; + } + + public String getNsInstanceName() { + return nsInstanceName; + } + + public void setNsInstanceName(String nsInstanceName) { + this.nsInstanceName = nsInstanceName; + } + + public String getNsInstanceDescription() { + return nsInstanceDescription; + } + + public void setNsInstanceDescription(String nsInstanceDescription) { + this.nsInstanceDescription = nsInstanceDescription; + } + + public String getNsdId() { + return nsdId; + } + + public void setNsdId(String nsdId) { + this.nsdId = nsdId; + } + + public List<NestedVnfInstance> getNestedVnfInstanceList() { + return nestedVnfInstanceList; + } + + public void setNestedVnfInstanceList(List<NestedVnfInstance> nestedVnfInstanceList) { + this.nestedVnfInstanceList = nestedVnfInstanceList; + } + + public List<NestedPnfInfo> getNestedPnfInfoList() { + return nestedPnfInfoList; + } + + public void setNestedPnfInfoList(List<NestedPnfInfo> nestedPnfInfoList) { + this.nestedPnfInfoList = nestedPnfInfoList; + } + + public String[] getNestedNsInstanceId() { + return nestedNsInstanceId; + } + + public void setNestedNsInstanceId(String[] nestedNsInstanceId) { + this.nestedNsInstanceId = nestedNsInstanceId; + } + + public String getNsState() { + return nsState; + } + + public void setNsState(String nsState) { + this.nsState = nsState; + } + +} diff --git a/src/main/java/com/cmcc/simulator/module/NestedPnfInfo.java b/src/main/java/com/cmcc/simulator/module/NestedPnfInfo.java new file mode 100644 index 0000000..6833d9b --- /dev/null +++ b/src/main/java/com/cmcc/simulator/module/NestedPnfInfo.java @@ -0,0 +1,45 @@ +package com.cmcc.simulator.module; + +public class NestedPnfInfo { + + private String pnfId; + private String pnfName; + private String pnfdId; + + public NestedPnfInfo() { + super(); + // TODO Auto-generated constructor stub + } + + public NestedPnfInfo(String pnfId, String pnfName, String pnfdId) { + super(); + this.pnfId = pnfId; + this.pnfName = pnfName; + this.pnfdId = pnfdId; + } + + public String getPnfId() { + return pnfId; + } + + public void setPnfId(String pnfId) { + this.pnfId = pnfId; + } + + public String getPnfName() { + return pnfName; + } + + public void setPnfName(String pnfName) { + this.pnfName = pnfName; + } + + public String getPnfdId() { + return pnfdId; + } + + public void setPnfdId(String pnfdId) { + this.pnfdId = pnfdId; + } + +} diff --git a/src/main/java/com/cmcc/simulator/module/NestedVnfInstance.java b/src/main/java/com/cmcc/simulator/module/NestedVnfInstance.java new file mode 100644 index 0000000..f9809aa --- /dev/null +++ b/src/main/java/com/cmcc/simulator/module/NestedVnfInstance.java @@ -0,0 +1,55 @@ +package com.cmcc.simulator.module; + +public class NestedVnfInstance { + + private String vnfInstanceId; + private String vnfInstanceName; + private String vnfdId; + private String instantiationState; + + public NestedVnfInstance() { + super(); + // TODO Auto-generated constructor stub + } + + public NestedVnfInstance(String vnfInstanceId, String vnfInstanceName, String vnfdId, String instantiationState) { + super(); + this.vnfInstanceId = vnfInstanceId; + this.vnfInstanceName = vnfInstanceName; + this.vnfdId = vnfdId; + this.instantiationState = instantiationState; + } + + public String getVnfInstanceId() { + return vnfInstanceId; + } + + public void setVnfInstanceId(String vnfInstanceId) { + this.vnfInstanceId = vnfInstanceId; + } + + public String getVnfInstanceName() { + return vnfInstanceName; + } + + public void setVnfInstanceName(String vnfInstanceName) { + this.vnfInstanceName = vnfInstanceName; + } + + public String getVnfdId() { + return vnfdId; + } + + public void setVnfdId(String vnfdId) { + this.vnfdId = vnfdId; + } + + public String getInstantiationState() { + return instantiationState; + } + + public void setInstantiationState(String instantiationState) { + this.instantiationState = instantiationState; + } + +} diff --git a/src/main/java/com/cmcc/simulator/module/NetworkSliceSubnet.java b/src/main/java/com/cmcc/simulator/module/NetworkSliceSubnet.java new file mode 100644 index 0000000..d86d1ba --- /dev/null +++ b/src/main/java/com/cmcc/simulator/module/NetworkSliceSubnet.java @@ -0,0 +1,47 @@ +package com.cmcc.simulator.module; + +import java.util.List; + +public class NetworkSliceSubnet { + + private String[] mfIdList; + private NsInstanceInfo nsInfo; + private List<SliceProfile> sliceProfileList; + + public NetworkSliceSubnet() { + super(); + // TODO Auto-generated constructor stub + } + + public NetworkSliceSubnet(String[] mfIdList, NsInstanceInfo nsInfo, List<SliceProfile> sliceProfileList) { + super(); + this.mfIdList = mfIdList; + this.nsInfo = nsInfo; + this.sliceProfileList = sliceProfileList; + } + + public String[] getMfIdList() { + return mfIdList; + } + + public void setMfIdList(String[] mfIdList) { + this.mfIdList = mfIdList; + } + + public NsInstanceInfo getNsInfo() { + return nsInfo; + } + + public void setNsInfo(NsInstanceInfo nsInfo) { + this.nsInfo = nsInfo; + } + + public List<SliceProfile> getSliceProfileList() { + return sliceProfileList; + } + + public void setSliceProfileList(List<SliceProfile> sliceProfileList) { + this.sliceProfileList = sliceProfileList; + } + +} diff --git a/src/main/java/com/cmcc/simulator/module/NewNsst.java b/src/main/java/com/cmcc/simulator/module/NewNsst.java new file mode 100644 index 0000000..f59713f --- /dev/null +++ b/src/main/java/com/cmcc/simulator/module/NewNsst.java @@ -0,0 +1,35 @@ +package com.cmcc.simulator.module; + +public class NewNsst { + + private String nsstId; + private String flavorId; + + public NewNsst() { + super(); + // TODO Auto-generated constructor stub + } + + public NewNsst(String nsstId, String flavorId) { + super(); + this.nsstId = nsstId; + this.flavorId = flavorId; + } + + public String getNsstId() { + return nsstId; + } + + public void setNsstId(String nsstId) { + this.nsstId = nsstId; + } + + public String getFlavorId() { + return flavorId; + } + + public void setFlavorId(String flavorId) { + this.flavorId = flavorId; + } + +} diff --git a/src/main/java/com/cmcc/simulator/module/NsInstanceInfo.java b/src/main/java/com/cmcc/simulator/module/NsInstanceInfo.java new file mode 100644 index 0000000..80d1d03 --- /dev/null +++ b/src/main/java/com/cmcc/simulator/module/NsInstanceInfo.java @@ -0,0 +1,108 @@ +package com.cmcc.simulator.module; + +import java.util.List; + +public class NsInstanceInfo { + + private String nsInstanceId; + private String nsInstanceName; + private String nsState; + private String nsInstanceDescription; + private String nsdId; + private String flavorId; + private List<VnfInstance> vnfInstance; // 企标样例和参数定义不一致,以样例为准 + private List<PnfInfo> pnfInfo; // 企标样例和参数定义不一致,以样例为准 + private List<NestedNsInstance> nestedNsInstance; + + public NsInstanceInfo() { + super(); + } + + public NsInstanceInfo(String nsInstanceId, String nsInstanceName, String nsState, String nsInstanceDescription, + String nsdId, String flavorId, List<VnfInstance> vnfInstanceList, List<PnfInfo> pnfInfoList, + List<NestedNsInstance> nestedNsInstance) { + super(); + this.nsInstanceId = nsInstanceId; + this.nsInstanceName = nsInstanceName; + this.nsState = nsState; + this.nsInstanceDescription = nsInstanceDescription; + this.nsdId = nsdId; + this.flavorId = flavorId; + this.vnfInstance = vnfInstanceList; + this.pnfInfo = pnfInfoList; + this.nestedNsInstance = nestedNsInstance; + } + + public String getNsInstanceId() { + return nsInstanceId; + } + + public void setNsInstanceId(String nsInstanceId) { + this.nsInstanceId = nsInstanceId; + } + + public String getNsInstanceName() { + return nsInstanceName; + } + + public void setNsInstanceName(String nsInstanceName) { + this.nsInstanceName = nsInstanceName; + } + + public String getNsState() { + return nsState; + } + + public void setNsState(String nsState) { + this.nsState = nsState; + } + + public String getNsInstanceDescription() { + return nsInstanceDescription; + } + + public void setNsInstanceDescription(String nsInstanceDescription) { + this.nsInstanceDescription = nsInstanceDescription; + } + + public String getNsdId() { + return nsdId; + } + + public void setNsdId(String nsdId) { + this.nsdId = nsdId; + } + + public String getFlavorId() { + return flavorId; + } + + public void setFlavorId(String flavorId) { + this.flavorId = flavorId; + } + + public List<VnfInstance> getVnfInstance() { + return vnfInstance; + } + + public void setVnfInstance(List<VnfInstance> vnfInstanceList) { + this.vnfInstance = vnfInstanceList; + } + + public List<PnfInfo> getPnfInfo() { + return pnfInfo; + } + + public void setPnfInfo(List<PnfInfo> pnfInfoList) { + this.pnfInfo = pnfInfoList; + } + + public List<NestedNsInstance> getNestedNsInstance() { + return nestedNsInstance; + } + + public void setNestedNsInstance(List<NestedNsInstance> nestedNsInstance) { + this.nestedNsInstance = nestedNsInstance; + } + +} diff --git a/src/main/java/com/cmcc/simulator/module/NsiInfo.java b/src/main/java/com/cmcc/simulator/module/NsiInfo.java new file mode 100644 index 0000000..97915bf --- /dev/null +++ b/src/main/java/com/cmcc/simulator/module/NsiInfo.java @@ -0,0 +1,34 @@ +package com.cmcc.simulator.module; + +public class NsiInfo { + + private String nsiId; + private String nsiName; + + public NsiInfo() { + super(); + } + + public NsiInfo(String nsiId, String nsiName) { + super(); + this.nsiId = nsiId; + this.nsiName = nsiName; + } + + public String getNsiId() { + return nsiId; + } + + public void setNsiId(String nsiId) { + this.nsiId = nsiId; + } + + public String getNsiName() { + return nsiName; + } + + public void setNsiName(String nsiName) { + this.nsiName = nsiName; + } + +} diff --git a/src/main/java/com/cmcc/simulator/module/Nssi.java b/src/main/java/com/cmcc/simulator/module/Nssi.java new file mode 100644 index 0000000..2164295 --- /dev/null +++ b/src/main/java/com/cmcc/simulator/module/Nssi.java @@ -0,0 +1,168 @@ +package com.cmcc.simulator.module; + +public class Nssi { + + private String nsstId; + + private String nssiName; + private String flavorId; + private String scriptName; + private String extension; + + private String nssiId; + private String nssiDesc; + private SliceProfile sliceProfile; + private NsiInfo nsiInfo; + + private int terminateNssiOption; + + private String nssiState; + private NetworkSliceSubnet networkSliceSubnet; + + private String snssai; + private NewNsst newNsst; + private String jobId; + + public Nssi() { + } + + public Nssi(String nsstId, String nssiName, String flavorId, String scriptName, String extension, String nssiId, + String nssiDesc, SliceProfile sliceProfile, NsiInfo nsiInfo, int terminateNssiOption, String nssiState, + NetworkSliceSubnet networkSliceSubnet) { + super(); + this.nsstId = nsstId; + this.nssiName = nssiName; + this.flavorId = flavorId; + this.scriptName = scriptName; + this.extension = extension; + this.nssiId = nssiId; + this.nssiDesc = nssiDesc; + this.sliceProfile = sliceProfile; + this.nsiInfo = nsiInfo; + this.terminateNssiOption = terminateNssiOption; + this.nssiState = nssiState; + this.networkSliceSubnet = networkSliceSubnet; + } + + public String getNsstId() { + return nsstId; + } + + public void setNsstId(String nsstId) { + this.nsstId = nsstId; + } + + public String getNssiName() { + return nssiName; + } + + public void setNssiName(String nssiName) { + this.nssiName = nssiName; + } + + public String getFlavorId() { + return flavorId; + } + + public void setFlavorId(String flavorId) { + this.flavorId = flavorId; + } + + public String getScriptName() { + return scriptName; + } + + public void setScriptName(String scriptName) { + this.scriptName = scriptName; + } + + public String getExtension() { + return extension; + } + + public void setExtension(String extension) { + this.extension = extension; + } + + public String getNssiId() { + return nssiId; + } + + public void setNssiId(String nssiId) { + this.nssiId = nssiId; + } + + public String getNssiDesc() { + return nssiDesc; + } + + public void setNssiDesc(String nssiDesc) { + this.nssiDesc = nssiDesc; + } + + public SliceProfile getSliceProfile() { + return sliceProfile; + } + + public void setSliceProfile(SliceProfile sliceProfile) { + this.sliceProfile = sliceProfile; + } + + public NsiInfo getNsiInfo() { + return nsiInfo; + } + + public void setNsiInfo(NsiInfo nsiInfo) { + this.nsiInfo = nsiInfo; + } + + public int getTerminateNssiOption() { + return terminateNssiOption; + } + + public void setTerminateNssiOption(int terminateNssiOption) { + this.terminateNssiOption = terminateNssiOption; + } + + public String getNssiState() { + return nssiState; + } + + public void setNssiState(String nssiState) { + this.nssiState = nssiState; + } + + public NetworkSliceSubnet getNetworkSliceSubnet() { + return networkSliceSubnet; + } + + public void setNetworkSliceSubnet(NetworkSliceSubnet networkSliceSubnet) { + this.networkSliceSubnet = networkSliceSubnet; + } + + public String getSnssai() { + return snssai; + } + + public void setSnssai(String snssai) { + this.snssai = snssai; + } + + public NewNsst getNewNsst() { + return newNsst; + } + + public void setNewNsst(NewNsst newNsst) { + this.newNsst = newNsst; + } + + public String getJobId() { + return jobId; + } + + public void setJobId(String jobId) { + this.jobId = jobId; + } + + +} diff --git a/src/main/java/com/cmcc/simulator/module/NssiInfo.java b/src/main/java/com/cmcc/simulator/module/NssiInfo.java new file mode 100644 index 0000000..9c53135 --- /dev/null +++ b/src/main/java/com/cmcc/simulator/module/NssiInfo.java @@ -0,0 +1,25 @@ +package com.cmcc.simulator.module; + +public class NssiInfo { + + private Nssi nssiInfo; + + public NssiInfo() { + super(); + // TODO Auto-generated constructor stub + } + + public NssiInfo(Nssi nssiInfo) { + super(); + this.nssiInfo = nssiInfo; + } + + public Nssi getNssiInfo() { + return nssiInfo; + } + + public void setNssiInfo(Nssi nssiInfo) { + this.nssiInfo = nssiInfo; + } + +} diff --git a/src/main/java/com/cmcc/simulator/module/NssiResponse.java b/src/main/java/com/cmcc/simulator/module/NssiResponse.java new file mode 100644 index 0000000..85f4903 --- /dev/null +++ b/src/main/java/com/cmcc/simulator/module/NssiResponse.java @@ -0,0 +1,34 @@ +package com.cmcc.simulator.module; + +public class NssiResponse { + + private String nssiId; + private String jobId; + + public NssiResponse() { + super(); + } + + public NssiResponse(String nssiId, String jobId) { + super(); + this.nssiId = nssiId; + this.jobId = jobId; + } + + public String getNssiId() { + return nssiId; + } + + public void setNssiId(String nssiId) { + this.nssiId = nssiId; + } + + public String getJobId() { + return jobId; + } + + public void setJobId(String jobId) { + this.jobId = jobId; + } + +} diff --git a/src/main/java/com/cmcc/simulator/module/PerfReq.java b/src/main/java/com/cmcc/simulator/module/PerfReq.java new file mode 100644 index 0000000..1b16eed --- /dev/null +++ b/src/main/java/com/cmcc/simulator/module/PerfReq.java @@ -0,0 +1,37 @@ +package com.cmcc.simulator.module; + +import java.util.List; + +public class PerfReq { + + private List<PerfReqEmbb> perfReqEmbbList; + private List<PerfReqUrllc> perfReqUrllcList; + + public PerfReq() { + super(); + // TODO Auto-generated constructor stub + } + + public PerfReq(List<PerfReqEmbb> perfReqEmbbList, List<PerfReqUrllc> perfReqUrllcList) { + super(); + this.perfReqEmbbList = perfReqEmbbList; + this.perfReqUrllcList = perfReqUrllcList; + } + + public List<PerfReqEmbb> getPerfReqEmbbList() { + return perfReqEmbbList; + } + + public void setPerfReqEmbbList(List<PerfReqEmbb> perfReqEmbbList) { + this.perfReqEmbbList = perfReqEmbbList; + } + + public List<PerfReqUrllc> getPerfReqUrllcList() { + return perfReqUrllcList; + } + + public void setPerfReqUrllcList(List<PerfReqUrllc> perfReqUrllcList) { + this.perfReqUrllcList = perfReqUrllcList; + } + +} diff --git a/src/main/java/com/cmcc/simulator/module/PerfReqEmbb.java b/src/main/java/com/cmcc/simulator/module/PerfReqEmbb.java new file mode 100644 index 0000000..a055ca3 --- /dev/null +++ b/src/main/java/com/cmcc/simulator/module/PerfReqEmbb.java @@ -0,0 +1,66 @@ +package com.cmcc.simulator.module; + +public class PerfReqEmbb { + + private int expDataRateDL; + private int expDataRateUL; + private int areaTrafficCapDL; + private int areaTrafficCapUL; + private int activityFactor; + + public PerfReqEmbb() { + super(); + // TODO Auto-generated constructor stub + } + + public PerfReqEmbb(int expDataRateDL, int expDataRateUL, int areaTrafficCapDL, int areaTrafficCapUL, + int activityFactor) { + super(); + this.expDataRateDL = expDataRateDL; + this.expDataRateUL = expDataRateUL; + this.areaTrafficCapDL = areaTrafficCapDL; + this.areaTrafficCapUL = areaTrafficCapUL; + this.activityFactor = activityFactor; + } + + public int getExpDataRateDL() { + return expDataRateDL; + } + + public void setExpDataRateDL(int expDataRateDL) { + this.expDataRateDL = expDataRateDL; + } + + public int getExpDataRateUL() { + return expDataRateUL; + } + + public void setExpDataRateUL(int expDataRateUL) { + this.expDataRateUL = expDataRateUL; + } + + public int getAreaTrafficCapDL() { + return areaTrafficCapDL; + } + + public void setAreaTrafficCapDL(int areaTrafficCapDL) { + this.areaTrafficCapDL = areaTrafficCapDL; + } + + public int getAreaTrafficCapUL() { + return areaTrafficCapUL; + } + + public void setAreaTrafficCapUL(int areaTrafficCapUL) { + this.areaTrafficCapUL = areaTrafficCapUL; + } + + public int getActivityFactor() { + return activityFactor; + } + + public void setActivityFactor(int activityFactor) { + this.activityFactor = activityFactor; + } + +} diff --git a/src/main/java/com/cmcc/simulator/module/PerfReqUrllc.java b/src/main/java/com/cmcc/simulator/module/PerfReqUrllc.java new file mode 100644 index 0000000..9a91a8e --- /dev/null +++ b/src/main/java/com/cmcc/simulator/module/PerfReqUrllc.java @@ -0,0 +1,116 @@ +package com.cmcc.simulator.module; + +public class PerfReqUrllc { + + private int e2eLatency; + private int jitter; + private int survivalTime; + private int csAvailability; + private int reliability; + private int expDataRate; + private int payloadSize; + private int trafficDensity; + private int connDensity; + private int serviceAreaDimension; + + public PerfReqUrllc() { + super(); + // TODO Auto-generated constructor stub + } + + public PerfReqUrllc(int e2eLatency, int jitter, int survivalTime, int csAvailability, int reliability, + int expDataRate, int payloadSize, int trafficDensity, int connDensity, int serviceAreaDimension) { + super(); + this.e2eLatency = e2eLatency; + this.jitter = jitter; + this.survivalTime = survivalTime; + this.csAvailability = csAvailability; + this.reliability = reliability; + this.expDataRate = expDataRate; + this.payloadSize = payloadSize; + this.trafficDensity = trafficDensity; + this.connDensity = connDensity; + this.serviceAreaDimension = serviceAreaDimension; + } + + public int getE2eLatency() { + return e2eLatency; + } + + public void setE2eLatency(int e2eLatency) { + this.e2eLatency = e2eLatency; + } + + public int getJitter() { + return jitter; + } + + public void setJitter(int jitter) { + this.jitter = jitter; + } + + public int getSurvivalTime() { + return survivalTime; + } + + public void setSurvivalTime(int survivalTime) { + this.survivalTime = survivalTime; + } + + public int getCsAvailability() { + return csAvailability; + } + + public void setCsAvailability(int csAvailability) { + this.csAvailability = csAvailability; + } + + public int getReliability() { + return reliability; + } + + public void setReliability(int reliability) { + this.reliability = reliability; + } + + public int getExpDataRate() { + return expDataRate; + } + + public void setExpDataRate(int expDataRate) { + this.expDataRate = expDataRate; + } + + public int getPayloadSize() { + return payloadSize; + } + + public void setPayloadSize(int payloadSize) { + this.payloadSize = payloadSize; + } + + public int getTrafficDensity() { + return trafficDensity; + } + + public void setTrafficDensity(int trafficDensity) { + this.trafficDensity = trafficDensity; + } + + public int getConnDensity() { + return connDensity; + } + + public void setConnDensity(int connDensity) { + this.connDensity = connDensity; + } + + public int getServiceAreaDimension() { + return serviceAreaDimension; + } + + public void setServiceAreaDimension(int serviceAreaDimension) { + this.serviceAreaDimension = serviceAreaDimension; + } + +} diff --git a/src/main/java/com/cmcc/simulator/module/PnfError.java b/src/main/java/com/cmcc/simulator/module/PnfError.java new file mode 100644 index 0000000..9e9ff63 --- /dev/null +++ b/src/main/java/com/cmcc/simulator/module/PnfError.java @@ -0,0 +1,35 @@ +package com.cmcc.simulator.module; + +public class PnfError { + + private String pnfId; + private String pnfErrorDesc; + + public PnfError() { + super(); + // TODO Auto-generated constructor stub + } + + public PnfError(String pnfId, String pnfErrorDesc) { + super(); + this.pnfId = pnfId; + this.pnfErrorDesc = pnfErrorDesc; + } + + public String getPnfId() { + return pnfId; + } + + public void setPnfId(String pnfId) { + this.pnfId = pnfId; + } + + public String getPnfErrorDesc() { + return pnfErrorDesc; + } + + public void setPnfErrorDesc(String pnfErrorDesc) { + this.pnfErrorDesc = pnfErrorDesc; + } + +} diff --git a/src/main/java/com/cmcc/simulator/module/PnfInfo.java b/src/main/java/com/cmcc/simulator/module/PnfInfo.java new file mode 100644 index 0000000..b078c45 --- /dev/null +++ b/src/main/java/com/cmcc/simulator/module/PnfInfo.java @@ -0,0 +1,44 @@ +package com.cmcc.simulator.module; + +public class PnfInfo { + private String pnfId; + private String pnfName; + private String pnfdId; + + public PnfInfo() { + super(); + // TODO Auto-generated constructor stub + } + + public PnfInfo(String pnfId, String pnfName, String pnfdId) { + super(); + this.pnfId = pnfId; + this.pnfName = pnfName; + this.pnfdId = pnfdId; + } + + public String getPnfId() { + return pnfId; + } + + public void setPnfId(String pnfId) { + this.pnfId = pnfId; + } + + public String getPnfName() { + return pnfName; + } + + public void setPnfName(String pnfName) { + this.pnfName = pnfName; + } + + public String getPnfdId() { + return pnfdId; + } + + public void setPnfdId(String pnfdId) { + this.pnfdId = pnfdId; + } + +} diff --git a/src/main/java/com/cmcc/simulator/module/ResponseDescriptor.java b/src/main/java/com/cmcc/simulator/module/ResponseDescriptor.java new file mode 100644 index 0000000..56f9bf9 --- /dev/null +++ b/src/main/java/com/cmcc/simulator/module/ResponseDescriptor.java @@ -0,0 +1,99 @@ +package com.cmcc.simulator.module; + +import java.util.List; + +public class ResponseDescriptor { + + private String status; + private int progress; + private String statusDescription; + private String errorCode; + private List<VnfError> vnfErrorList; + private List<PnfError> pnfErrorList; + private String responseId; + private List<ResponseHistory> responseHistoryList; + + public ResponseDescriptor() { + super(); + // TODO Auto-generated constructor stub + } + + public ResponseDescriptor(String status, int progress, String statusDescription, String errorCode, + List<VnfError> vnfErrorList, List<PnfError> pnfErrorList, String responseId, + List<ResponseHistory> responseHistoryList) { + super(); + this.status = status; + this.progress = progress; + this.statusDescription = statusDescription; + this.errorCode = errorCode; + this.vnfErrorList = vnfErrorList; + this.pnfErrorList = pnfErrorList; + this.responseId = responseId; + this.responseHistoryList = responseHistoryList; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public int getProgress() { + return progress; + } + + public void setProgress(int progress) { + this.progress = progress; + } + + public String getStatusDescription() { + return statusDescription; + } + + public void setStatusDescription(String statusDescription) { + this.statusDescription = statusDescription; + } + + public String getErrorCode() { + return errorCode; + } + + public void setErrorCode(String errorCode) { + this.errorCode = errorCode; + } + + public List<VnfError> getVnfErrorList() { + return vnfErrorList; + } + + public void setVnfErrorList(List<VnfError> vnfErrorList) { + this.vnfErrorList = vnfErrorList; + } + + public List<PnfError> getPnfErrorList() { + return pnfErrorList; + } + + public void setPnfErrorList(List<PnfError> pnfErrorList) { + this.pnfErrorList = pnfErrorList; + } + + public String getResponseId() { + return responseId; + } + + public void setResponseId(String responseId) { + this.responseId = responseId; + } + + public List<ResponseHistory> getResponseHistoryList() { + return responseHistoryList; + } + + public void setResponseHistoryList(List<ResponseHistory> responseHistoryList) { + this.responseHistoryList = responseHistoryList; + } + +} diff --git a/src/main/java/com/cmcc/simulator/module/ResponseHistory.java b/src/main/java/com/cmcc/simulator/module/ResponseHistory.java new file mode 100644 index 0000000..8260d22 --- /dev/null +++ b/src/main/java/com/cmcc/simulator/module/ResponseHistory.java @@ -0,0 +1,88 @@ +package com.cmcc.simulator.module; + +import java.util.List; + +public class ResponseHistory { + + private String status; + private int progress; + private String statusDescription; + private String errorCode; + private List<VnfError> vnfErrorList; + private List<PnfError> pnfErrorList; + private String responseId; + + public ResponseHistory() { + super(); + // TODO Auto-generated constructor stub + } + + public ResponseHistory(String status, int progress, String statusDescription, String errorCode, + List<VnfError> vnfErrorList, List<PnfError> pnfErrorList, String responseId) { + super(); + this.status = status; + this.progress = progress; + this.statusDescription = statusDescription; + this.errorCode = errorCode; + this.vnfErrorList = vnfErrorList; + this.pnfErrorList = pnfErrorList; + this.responseId = responseId; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public int getProgress() { + return progress; + } + + public void setProgress(int progress) { + this.progress = progress; + } + + public String getStatusDescription() { + return statusDescription; + } + + public void setStatusDescription(String statusDescription) { + this.statusDescription = statusDescription; + } + + public String getErrorCode() { + return errorCode; + } + + public void setErrorCode(String errorCode) { + this.errorCode = errorCode; + } + + public List<VnfError> getVnfErrorList() { + return vnfErrorList; + } + + public void setVnfErrorList(List<VnfError> vnfErrorList) { + this.vnfErrorList = vnfErrorList; + } + + public List<PnfError> getPnfErrorList() { + return pnfErrorList; + } + + public void setPnfErrorList(List<PnfError> pnfErrorList) { + this.pnfErrorList = pnfErrorList; + } + + public String getResponseId() { + return responseId; + } + + public void setResponseId(String responseId) { + this.responseId = responseId; + } + +} diff --git a/src/main/java/com/cmcc/simulator/module/SliceProfile.java b/src/main/java/com/cmcc/simulator/module/SliceProfile.java new file mode 100644 index 0000000..b0d08ee --- /dev/null +++ b/src/main/java/com/cmcc/simulator/module/SliceProfile.java @@ -0,0 +1,168 @@ +package com.cmcc.simulator.module; + +public class SliceProfile { + private String[] snssaiList; + private String sliceProfileId; + private String[] plmnIdList; + private PerfReq perfReq; + + private int maxNumberofUEs; + private int maxNumberofPDUSession; + private int totalDataVolume; + private String upfDeployLocation; + private String[] coverageAreaTAList; + private int latency; + private String ueMobilityLevel; + private String resourceSharingLevel; + + private int terminateNssiOption = 0; + private String scriptName = "CN1"; + + private String nssiId; + + public SliceProfile() { + super(); + } + + public SliceProfile(String[] snssaiList, String sliceProfileId, String[] plmnIdList, PerfReq perfReq, + int maxNumberofUEs, int maxNumberofPDUSession, int totalDataVolume, String upfDeployLocation, + String[] coverageAreaTAList, int latency, String ueMobilityLevel, String resourceSharingLevel, + int terminateNssiOption, String scriptName) { + super(); + this.snssaiList = snssaiList; + this.sliceProfileId = sliceProfileId; + this.plmnIdList = plmnIdList; + this.perfReq = perfReq; + this.maxNumberofUEs = maxNumberofUEs; + this.maxNumberofPDUSession = maxNumberofPDUSession; + this.totalDataVolume = totalDataVolume; + this.upfDeployLocation = upfDeployLocation; + this.coverageAreaTAList = coverageAreaTAList; + this.latency = latency; + this.ueMobilityLevel = ueMobilityLevel; + this.resourceSharingLevel = resourceSharingLevel; + this.scriptName = scriptName; + this.terminateNssiOption = terminateNssiOption; + } + + public String[] getSnssaiList() { + return snssaiList; + } + + public void setSnssaiList(String[] snssaiList) { + this.snssaiList = snssaiList; + } + + public String getSliceProfileId() { + return sliceProfileId; + } + + public void setSliceProfileId(String sliceProfileId) { + this.sliceProfileId = sliceProfileId; + } + + public String[] getPlmnIdList() { + return plmnIdList; + } + + public void setPlmnIdList(String[] plmnIdList) { + this.plmnIdList = plmnIdList; + } + + public PerfReq getPerfReq() { + return perfReq; + } + + public void setPerfReq(PerfReq perfReq) { + this.perfReq = perfReq; + } + + public int getMaxNumberofUEs() { + return maxNumberofUEs; + } + + public void setMaxNumberofUEs(int maxNumberofUEs) { + this.maxNumberofUEs = maxNumberofUEs; + } + + public int getMaxNumberofPDUSession() { + return maxNumberofPDUSession; + } + + public void setMaxNumberofPDUSession(int maxNumberofPDUSession) { + this.maxNumberofPDUSession = maxNumberofPDUSession; + } + + public int getTotalDataVolume() { + return totalDataVolume; + } + + public void setTotalDataVolume(int totalDataVolume) { + this.totalDataVolume = totalDataVolume; + } + + public String getUpfDeployLocation() { + return upfDeployLocation; + } + + public void setUpfDeployLocation(String upfDeployLocation) { + this.upfDeployLocation = upfDeployLocation; + } + + public String[] getCoverageAreaTAList() { + return coverageAreaTAList; + } + + public void setCoverageAreaTAList(String[] coverageAreaTAList) { + this.coverageAreaTAList = coverageAreaTAList; + } + + public int getLatency() { + return latency; + } + + public void setLatency(int latency) { + this.latency = latency; + } + + public String getUeMobilityLevel() { + return ueMobilityLevel; + } + + public void setUeMobilityLevel(String ueMobilityLevel) { + this.ueMobilityLevel = ueMobilityLevel; + } + + public String getResourceSharingLevel() { + return resourceSharingLevel; + } + + public void setResourceSharingLevel(String resourceSharingLevel) { + this.resourceSharingLevel = resourceSharingLevel; + } + + public String getNssiId() { + return nssiId; + } + + public void setNssiId(String nssiId) { + this.nssiId = nssiId; + } + + public int getTerminateNssiOption() { + return terminateNssiOption; + } + + public void setTerminateNssiOption(int terminateNssiOption) { + this.terminateNssiOption = terminateNssiOption; + } + + public String getScriptName() { + return scriptName; + } + + public void setScriptName(String scriptName) { + this.scriptName = scriptName; + } + +} diff --git a/src/main/java/com/cmcc/simulator/module/VnfError.java b/src/main/java/com/cmcc/simulator/module/VnfError.java new file mode 100644 index 0000000..042df65 --- /dev/null +++ b/src/main/java/com/cmcc/simulator/module/VnfError.java @@ -0,0 +1,35 @@ +package com.cmcc.simulator.module; + +public class VnfError { + + private String vnfInstanceId; + private String vnfErrorDesc; + + public VnfError() { + super(); + // TODO Auto-generated constructor stub + } + + public VnfError(String vnfInstanceId, String vnfErrorDesc) { + super(); + this.vnfInstanceId = vnfInstanceId; + this.vnfErrorDesc = vnfErrorDesc; + } + + public String getVnfInstanceId() { + return vnfInstanceId; + } + + public void setVnfInstanceId(String vnfInstanceId) { + this.vnfInstanceId = vnfInstanceId; + } + + public String getVnfErrorDesc() { + return vnfErrorDesc; + } + + public void setVnfErrorDesc(String vnfErrorDesc) { + this.vnfErrorDesc = vnfErrorDesc; + } + +} diff --git a/src/main/java/com/cmcc/simulator/module/VnfInstance.java b/src/main/java/com/cmcc/simulator/module/VnfInstance.java new file mode 100644 index 0000000..1f306d7 --- /dev/null +++ b/src/main/java/com/cmcc/simulator/module/VnfInstance.java @@ -0,0 +1,55 @@ +package com.cmcc.simulator.module; + +public class VnfInstance { + + private String vnfInstanceId; + private String vnfInstanceName; + private String vnfdId; + private String instantiationState; + + public VnfInstance() { + super(); + // TODO Auto-generated constructor stub + } + + public VnfInstance(String vnfInstanceId, String vnfInstanceName, String vnfdId, String instantiationState) { + super(); + this.vnfInstanceId = vnfInstanceId; + this.vnfInstanceName = vnfInstanceName; + this.vnfdId = vnfdId; + this.instantiationState = instantiationState; + } + + public String getVnfInstanceId() { + return vnfInstanceId; + } + + public void setVnfInstanceId(String vnfInstanceId) { + this.vnfInstanceId = vnfInstanceId; + } + + public String getVnfInstanceName() { + return vnfInstanceName; + } + + public void setVnfInstanceName(String vnfInstanceName) { + this.vnfInstanceName = vnfInstanceName; + } + + public String getVnfdId() { + return vnfdId; + } + + public void setVnfdId(String vnfdId) { + this.vnfdId = vnfdId; + } + + public String getInstantiationState() { + return instantiationState; + } + + public void setInstantiationState(String instantiationState) { + this.instantiationState = instantiationState; + } + +} diff --git a/src/main/java/com/cmcc/simulator/service/SimulatorService.java b/src/main/java/com/cmcc/simulator/service/SimulatorService.java new file mode 100644 index 0000000..0e1757e --- /dev/null +++ b/src/main/java/com/cmcc/simulator/service/SimulatorService.java @@ -0,0 +1,301 @@ +package com.cmcc.simulator.service; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +import com.alibaba.fastjson.JSON; +import com.cmcc.simulator.xml.CV; +import com.cmcc.simulator.xml.FileReadyEvent; +import com.cmcc.simulator.xml.GZIPUtil; +import com.cmcc.simulator.xml.Instance; +import com.cmcc.simulator.xml.SN; +import com.cmcc.simulator.xml.Utils; +import com.cmcc.simulator.xml.V; + +@Component +public class SimulatorService { + + @Autowired + RestTemplate restTemplate; + + private List<String> snssaiIds = new ArrayList<>(); + + private List<String> nssiIds = new ArrayList<>(); + + private List<String> jobIds = new ArrayList<>(); + + private List<String> sliceProfileIds = new ArrayList<>(); + + private List<String> nsstIds = new ArrayList<>(); + + private Map<String, Integer> jobCheckCount = new HashMap<String,Integer>(); + + private List<String> activatedSlices = new ArrayList<>(); + + @Value("${filepath}") + private String filePath; + + @Value("${notifyurl}") + private String url; + + @Value("${amffilepath}") + private String amfFilePath; + + @Value("${upffilepath}") + private String upfFilePath; + + public List<String> getActivatedSlices() { + return activatedSlices; + } + + public List<String> getSnssaiIds() { + return snssaiIds; + } + + public List<String> getNssiIds() { + return nssiIds; + } + + public List<String> getJobIds() { + return jobIds; + } + + public List<String> getSliceProfileIds() { + return sliceProfileIds; + } + + public List<String> getNsstIds() { + return nsstIds; + } + + public synchronized void addActivatedSlices(String snssaiId) { + if (!activatedSlices.contains(snssaiId)) + activatedSlices.add(snssaiId); + } + + public synchronized void removeActivatedSlices(String snssaiId) { + if (activatedSlices.contains(snssaiId)) + activatedSlices.remove(snssaiId); + } + + public synchronized void addNsstIds(String nsstId) { + if (!nsstIds.contains(nsstId)) + nsstIds.add(nsstId); + } + + public synchronized void removeNsstIds(String nsstId) { + if (nsstIds.contains(nsstId)) + nsstIds.remove(nsstId); + } + + public synchronized void addSliceProfileIds(String sliceProfileId) { + if (!sliceProfileIds.contains(sliceProfileId)) + sliceProfileIds.add(sliceProfileId); + } + + public synchronized void removeSliceProfileIds(String sliceProfileId) { + if (sliceProfileIds.contains(sliceProfileId)) + sliceProfileIds.remove(sliceProfileId); + } + + public synchronized void addSnssaiIds(String snssaiId) { + if (!snssaiIds.contains(snssaiId)) + snssaiIds.add(snssaiId); + } + + public synchronized void removeSnssaiIds(String snssaiId) { + if (snssaiIds.contains(snssaiId)) + snssaiIds.remove(snssaiId); + } + + public synchronized void addNssiIds(String nssiId) { + if (!nssiIds.contains(nssiId)) + nssiIds.add(nssiId); + } + + public synchronized void removeNssiIds(String nssiId) { + if (nssiIds.contains(nssiId)) + nssiIds.remove(nssiId); + } + + public synchronized void addJobIds(String jobId) { + if (!jobIds.contains(jobId)) + jobIds.add(jobId); + } + + public synchronized void removeJobIds(String jobId) { + if (jobIds.contains(jobId)) + jobIds.remove(jobId); + } + + public void createAMF(List<String> nsstIds) throws Exception { + List<Instance> objects = new ArrayList<>(); + Instance object1 = new Instance(); + Instance object2 = new Instance(); + List<SN> sns1 = new ArrayList<>(); + List<SN> sns2 = new ArrayList<>(); + CV cv1 = new CV(); + CV cv2 = new CV(); + List<CV> cvs1 = new ArrayList<>(); + List<CV> cvs2 = new ArrayList<>(); + + V v1 = new V("1", 1); + V v2 = new V("2", 2); + V v3 = new V("3", 3); + List<V> vs = new ArrayList<>(); + vs.add(v1); + vs.add(v2); + vs.add(v3); + + nsstIds.forEach(nssiId -> { + SN sn1 = new SN("AMF.RegSub.460_08_" + nssiId, (int) (Math.random() * (100 - 1) + 1)); + SN sn2 = new SN("AMF.RegSub.460_08_" + nssiId, (int) (Math.random() * (100 - 1) + 1)); + sns1.add(sn1); + sns2.add(sn2); + cv1.setI("46"); + cv1.setSns(sns1); + cv2.setI("46"); + cv2.setSns(sns2); + }); + cvs1.add(cv1); + cvs2.add(cv2); + object1.setCvs(cvs1); + object2.setCvs(cvs2); + object2.setVs(vs); + object1.setVs(vs); + objects.add(object1); + objects.add(object2); + String str = Utils.createAmfFile(objects); + String xmlPath = filePath + "/AMF.xml"; + BufferedWriter bfw = new BufferedWriter(new FileWriter(new File(xmlPath))); + bfw.write(str); + bfw.close(); + GZIPUtil.doCompressFileToGz(xmlPath); + } + + public void createUPF(List<String> nsstIds) throws Exception { + List<Instance> objects = new ArrayList<>(); + Instance object1 = new Instance(); + Instance object2 = new Instance(); + + List<SN> sns1 = new ArrayList<>(); + List<SN> sns2 = new ArrayList<>(); + List<SN> sns3 = new ArrayList<>(); + List<SN> sns4 = new ArrayList<>(); + + List<CV> cvs1 = new ArrayList<>(); + List<CV> cvs2 = new ArrayList<>(); + + V v1 = new V("1", 1); + V v2 = new V("2", 2); + V v3 = new V("3", 3); + List<V> vs = new ArrayList<>(); + vs.add(v1); + vs.add(v2); + vs.add(v3); + + CV cv1 = new CV(); + CV cv2 = new CV(); + CV cv3 = new CV(); + CV cv4 = new CV(); + + nsstIds.forEach(nssiId -> { + SN sn1 = new SN("UPF.N3IncPkt.340_110_" + nssiId, (int) (Math.random() * (100 - 1) + 1)); + sns1.add(sn1); + cv1.setI("9"); + cv1.setSns(sns1); + + SN sn2 = new SN("UPF.N3OgOct.340_110_" + nssiId, (int) (Math.random() * (100 - 1) + 1)); + sns2.add(sn2); + cv2.setI("11"); + cv2.setSns(sns2); + + + SN sn3 = new SN("UPF.N3IncPkt.340_110_" + nssiId, (int) (Math.random() * (100 - 1) + 1)); + sns3.add(sn3); + cv3.setI("9"); + cv3.setSns(sns3); + + SN sn4 = new SN("UPF.N3OgOct.340_110_" + nssiId, (int) (Math.random() * (100 - 1) + 1)); + sns4.add(sn4); + cv4.setI("11"); + cv4.setSns(sns4); + + }); + cvs1.add(cv1); + cvs1.add(cv2); + cvs2.add(cv3); + cvs2.add(cv4); + object1.setCvs(cvs1); + object2.setCvs(cvs2); + object2.setVs(vs); + object1.setVs(vs); + objects.add(object1); + objects.add(object2); + String str = Utils.createUPFFile(objects); + String xmlPath = filePath + "/UPF.xml"; + BufferedWriter bfw = new BufferedWriter(new FileWriter(new File(xmlPath))); + bfw.write(str); + bfw.close(); + GZIPUtil.doCompressFileToGz(xmlPath); + } + + public void notify(FileReadyEvent event) throws Exception { + SimulatorService.sendHttpPost(url, JSON.toJSONString(event)); + } + + public void gzipFiles() { + File[] sources = new File[] { new File(amfFilePath), + new File(upfFilePath) }; + // Define a the *.tar file ,the file in sources will be tar to the target + File target = new File(filePath + "/PM.tar"); + // compress the files into *.tar.gz + GZIPUtil.compress(filePath, GZIPUtil.pack(sources, target)); + } + + public void delFiles() { + Utils.delFile(new File(filePath + "/AMF.xml")); + Utils.delFile(new File(filePath + "/UPF.xml")); + Utils.delFile(new File(amfFilePath)); + Utils.delFile(new File(upfFilePath)); + Utils.delFile(new File(filePath + "/PM.tar")); +// Utils.delFile(new File(filePath + "/PM.tar.gz")); + } + public static void sendHttpPost(String url, String JSONBody) throws Exception { + CloseableHttpClient httpClient = HttpClients.createDefault(); + HttpPost httpPost = new HttpPost(url); + httpPost.addHeader("Content-Type", "application/json"); + httpPost.setEntity(new StringEntity(JSONBody)); + CloseableHttpResponse response = httpClient.execute(httpPost); + + response.close(); + httpClient.close(); + } + + public void updateJobCheckCount(String jobId, Integer count) { + if (count != 4) { + jobCheckCount.put(jobId, count); + } else { + jobCheckCount.remove(jobId); + } + } + + public Map<String, Integer> getJobCheckCount() { + return jobCheckCount; + } +} diff --git a/src/main/java/com/cmcc/simulator/util/StringUtil.java b/src/main/java/com/cmcc/simulator/util/StringUtil.java new file mode 100644 index 0000000..002e7f0 --- /dev/null +++ b/src/main/java/com/cmcc/simulator/util/StringUtil.java @@ -0,0 +1,21 @@ +package com.cmcc.simulator.util; + +public class StringUtil { + + public static String randomStr(int len) { + if (len == 0) { + return ""; + } + int a = (int) (Math.random() * 3); + if (a == 0) { + return ((int) (Math.random() * 10)) + randomStr(len - 1); + } else { + return ((char) ((int) (Math.random() * 26) + 65)) + randomStr(len - 1); + } + } + +// public static void main(String[] args) { +// System.out.println(randomStr(2)); +// } + +} diff --git a/src/main/java/com/cmcc/simulator/xml/CV.java b/src/main/java/com/cmcc/simulator/xml/CV.java new file mode 100644 index 0000000..492ff75 --- /dev/null +++ b/src/main/java/com/cmcc/simulator/xml/CV.java @@ -0,0 +1,39 @@ +package com.cmcc.simulator.xml; + +import java.util.List; + +import javax.xml.bind.annotation.XmlAttribute; + +public class CV { + + private List<SN> sns; + private String i; + + public CV() { + super(); + } + + public CV(List<SN> sns, String i) { + super(); + this.sns = sns; + this.i = i; + } + + public List<SN> getSns() { + return sns; + } + + public void setSns(List<SN> sns) { + this.sns = sns; + } + + @XmlAttribute(name = "i") + public String getI() { + return i; + } + + public void setI(String i) { + this.i = i; + } + +} diff --git a/src/main/java/com/cmcc/simulator/xml/FileHeader.java b/src/main/java/com/cmcc/simulator/xml/FileHeader.java new file mode 100644 index 0000000..9847458 --- /dev/null +++ b/src/main/java/com/cmcc/simulator/xml/FileHeader.java @@ -0,0 +1,94 @@ +package com.cmcc.simulator.xml; + +import java.util.Date; + +import javax.xml.bind.annotation.XmlElement; + +public class FileHeader { + private String vendorName; + private String elementType; + private String pmVersion; + private String timeZone; + private int period; + private String timeStamp; + private String startTime; + + public FileHeader() { + } + + public FileHeader(String vendorName, String elementType, String pmVersion, String timeZone, int period, + String timeStamp, String startTime) { + super(); + this.vendorName = vendorName; + this.elementType = elementType; + this.pmVersion = pmVersion; + this.timeZone = timeZone; + this.period = period; + this.timeStamp = timeStamp; + this.startTime = startTime; + } + + @XmlElement(name="VendorName") + public String getVendorName() { + return vendorName; + } + + public void setVendorName(String vendorName) { + this.vendorName = vendorName; + } + + @XmlElement(name="ElementType") + public String getElementType() { + return elementType; + } + + public void setElementType(String elementType) { + this.elementType = elementType; + } + + @XmlElement(name="PmVersion") + public String getPmVersion() { + return pmVersion; + } + + public void setPmVersion(String pmVersion) { + this.pmVersion = pmVersion; + } + + @XmlElement(name="TimeZone") + public String getTimeZone() { + return timeZone; + } + + public void setTimeZone(String timeZone) { + this.timeZone = timeZone; + } + + @XmlElement(name="Period") + public int getPeriod() { + return period; + } + + public void setPeriod(int period) { + this.period = period; + } + + @XmlElement(name="TimeStamp") + public String getTimeStamp() { + return timeStamp; + } + + public void setTimeStamp(String timeStamp) { + this.timeStamp = timeStamp; + } + + @XmlElement(name="StartTime") + public String getStartTime() { + return startTime; + } + + public void setStartTime(String startTime) { + this.startTime = startTime; + } + +} diff --git a/src/main/java/com/cmcc/simulator/xml/FileReadyEvent.java b/src/main/java/com/cmcc/simulator/xml/FileReadyEvent.java new file mode 100644 index 0000000..f14f22f --- /dev/null +++ b/src/main/java/com/cmcc/simulator/xml/FileReadyEvent.java @@ -0,0 +1,61 @@ +package com.cmcc.simulator.xml; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +public class FileReadyEvent implements Serializable { + + private static final long serialVersionUID = 1L; + + private String nfvoid; + private String datasource; + private String sourceid; + private String createat; + private List<String> fileuri; + + public String getNfvoid() { + return nfvoid; + } + + public void setNfvoid(String nfvoid) { + this.nfvoid = nfvoid; + } + + public String getDatasource() { + return datasource; + } + + public void setDatasource(String datasource) { + this.datasource = datasource; + } + + public String getSourceid() { + return sourceid; + } + + public void setSourceid(String sourceid) { + this.sourceid = sourceid; + } + + public String getCreateat() { + return createat; + } + + public void setCreateat(String createat) { + this.createat = createat; + } + + public List<String> getFileuri() { + return fileuri; + } + + public void setFileuri(List<String> fileuri) { + this.fileuri = fileuri; + } + + public static long getSerialversionuid() { + return serialVersionUID; + } + +} diff --git a/src/main/java/com/cmcc/simulator/xml/GZIPUtil.java b/src/main/java/com/cmcc/simulator/xml/GZIPUtil.java new file mode 100644 index 0000000..3216a8c --- /dev/null +++ b/src/main/java/com/cmcc/simulator/xml/GZIPUtil.java @@ -0,0 +1,135 @@ +package com.cmcc.simulator.xml; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.zip.GZIPOutputStream; + +import org.apache.commons.compress.archivers.tar.TarArchiveEntry; +import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; +import org.apache.commons.compress.utils.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class GZIPUtil { + + private static final Logger logger = LoggerFactory.getLogger(GZIPUtil.class); + public static File pack(File[] sources, File target) { + FileOutputStream out = null; + try { + out = new FileOutputStream(target); + } catch (FileNotFoundException e1) { + e1.printStackTrace(); + } + TarArchiveOutputStream os = new TarArchiveOutputStream(out); + for (File file : sources) { + try { + TarArchiveEntry tae = new TarArchiveEntry(file); + tae.setName(file.getName()); + os.putArchiveEntry(tae); +// os.putArchiveEntry(tae); + IOUtils.copy(new FileInputStream(file), os); + os.closeArchiveEntry(); + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (os != null) { + try { + os.flush(); + os.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + return target; + } + + + public static File compress(String filePath, File source) { + + File target = new File(filePath + "/" + source.getName() + ".gz"); + FileInputStream in = null; + GZIPOutputStream out = null; + try { + in = new FileInputStream(source); + out = new GZIPOutputStream(new FileOutputStream(target)); + byte[] array = new byte[1024]; + int number = -1; + while ((number = in.read(array, 0, array.length)) != -1) { + out.write(array, 0, number); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + return null; + } catch (IOException e) { + e.printStackTrace(); + return null; + } finally { + if (in != null) { + try { + in.close(); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + if (out != null) { + try { + out.close(); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + } + return target; + } + + public static void doCompressFileToGz(String inFileName) { + try { + + logger.debug("Creating the GZIP output stream."); + String outFileName = inFileName + ".gz"; + GZIPOutputStream out = null; + try { + out = new GZIPOutputStream(new FileOutputStream(outFileName)); + } catch (FileNotFoundException e) { + logger.info("Could not create file: " + outFileName); + System.exit(1); + } + + logger.debug("Opening the input file."); + FileInputStream in = null; + try { + in = new FileInputStream(inFileName); + } catch (FileNotFoundException e) { + logger.error("File not found. " + inFileName); + System.exit(1); + } + + logger.debug("Transfering bytes from input file to GZIP Format."); + byte[] buf = new byte[1024]; + int len; + while ((len = in.read(buf)) > 0) { + out.write(buf, 0, len); + } + in.close(); + + logger.info("Completing the GZIP file"); + out.finish(); + out.close(); + + } catch (IOException e) { + e.printStackTrace(); + System.exit(1); + } + } +} diff --git a/src/main/java/com/cmcc/simulator/xml/Instance.java b/src/main/java/com/cmcc/simulator/xml/Instance.java new file mode 100644 index 0000000..c6e0f75 --- /dev/null +++ b/src/main/java/com/cmcc/simulator/xml/Instance.java @@ -0,0 +1,39 @@ +package com.cmcc.simulator.xml; + +import java.util.List; + +import javax.xml.bind.annotation.XmlElement; + +public class Instance { + List<V> vs; + List<CV> cvs; + + public Instance() { + super(); + } + + public Instance(List<V> vs, List<CV> cvs) { + super(); + this.vs = vs; + this.cvs = cvs; + } + + @XmlElement(name="V") + public List<V> getVs() { + return vs; + } + + public void setVs(List<V> vs) { + this.vs = vs; + } + + @XmlElement(name="CV") + public List<CV> getCvs() { + return cvs; + } + + public void setCvs(List<CV> cvs) { + this.cvs = cvs; + } + +} diff --git a/src/main/java/com/cmcc/simulator/xml/Measurements.java b/src/main/java/com/cmcc/simulator/xml/Measurements.java new file mode 100644 index 0000000..99eb5df --- /dev/null +++ b/src/main/java/com/cmcc/simulator/xml/Measurements.java @@ -0,0 +1,52 @@ +package com.cmcc.simulator.xml; + +import java.util.List; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; + +public class Measurements { + + String objectType; + List<N> n; + PmData pmData; + public Measurements() { + super(); + } + + public Measurements(String objectType, List<N> n, PmData pmData) { + super(); + this.objectType = objectType; + this.n = n; + this.pmData = pmData; + } + + @XmlElementWrapper(name = "PmName") + @XmlElement(name = "N") + public List<N> getN() { + return n; + } + + public void setN(List<N> n) { + this.n = n; + } + + @XmlElement(name = "ObjectType") + public String getObjectType() { + return objectType; + } + + public void setObjectType(String objectType) { + this.objectType = objectType; + } + + @XmlElement(name = "PmData") + public PmData getPmData() { + return pmData; + } + + public void setPmData(PmData pmData) { + this.pmData = pmData; + } + +} diff --git a/src/main/java/com/cmcc/simulator/xml/N.java b/src/main/java/com/cmcc/simulator/xml/N.java new file mode 100644 index 0000000..0fe9978 --- /dev/null +++ b/src/main/java/com/cmcc/simulator/xml/N.java @@ -0,0 +1,39 @@ +package com.cmcc.simulator.xml; + +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlValue; + +public class N { + String i; + String value; + + public N() { + super(); + // TODO Auto-generated constructor stub + } + + public N(String i, String value) { + super(); + this.i = i; + this.value = value; + } + + @XmlAttribute(name = "i") + public String getI() { + return i; + } + + public void setI(String i) { + this.i = i; + } + + public String getValue() { + return value; + } + + @XmlValue + public void setValue(String value) { + this.value = value; + } + +} diff --git a/src/main/java/com/cmcc/simulator/xml/PmData.java b/src/main/java/com/cmcc/simulator/xml/PmData.java new file mode 100644 index 0000000..b572ace --- /dev/null +++ b/src/main/java/com/cmcc/simulator/xml/PmData.java @@ -0,0 +1,30 @@ +package com.cmcc.simulator.xml; + +import java.util.List; + +import javax.xml.bind.annotation.XmlElement; + +public class PmData { + + List<Instance> objects; + + public PmData() { + super(); + // TODO Auto-generated constructor stub + } + + public PmData(List<Instance> objects) { + super(); + this.objects = objects; + } + + @XmlElement(name="Object") + public List<Instance> getObjects() { + return objects; + } + + public void setObjects(List<Instance> objects) { + this.objects = objects; + } + +} diff --git a/src/main/java/com/cmcc/simulator/xml/PmFile.java b/src/main/java/com/cmcc/simulator/xml/PmFile.java new file mode 100644 index 0000000..1a49e15 --- /dev/null +++ b/src/main/java/com/cmcc/simulator/xml/PmFile.java @@ -0,0 +1,40 @@ +package com.cmcc.simulator.xml; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "PmFile") +public class PmFile { + + private FileHeader fileHeader; + private Measurements measurements; + + public PmFile() { + super(); + } + + public PmFile(FileHeader fileHeader, Measurements measurements) { + super(); + this.fileHeader = fileHeader; + this.measurements = measurements; + } + + @XmlElement(name="FileHeader") + public FileHeader getFileHeader() { + return fileHeader; + } + + public void setFileHeader(FileHeader fileHeader) { + this.fileHeader = fileHeader; + } + + @XmlElement(name="Measurements") + public Measurements getMeasurements() { + return measurements; + } + + public void setMeasurements(Measurements measurements) { + this.measurements = measurements; + } + +} diff --git a/src/main/java/com/cmcc/simulator/xml/PmName.java b/src/main/java/com/cmcc/simulator/xml/PmName.java new file mode 100644 index 0000000..a216c6e --- /dev/null +++ b/src/main/java/com/cmcc/simulator/xml/PmName.java @@ -0,0 +1,20 @@ +package com.cmcc.simulator.xml; + +import java.util.List; + +import javax.xml.bind.annotation.XmlElement; + +public class PmName { + + List<N> ns; + + @XmlElement(name = "N") + public List<N> getNs() { + return ns; + } + + public void setNs(List<N> ns) { + this.ns = ns; + } + +} diff --git a/src/main/java/com/cmcc/simulator/xml/SN.java b/src/main/java/com/cmcc/simulator/xml/SN.java new file mode 100644 index 0000000..fcb9001 --- /dev/null +++ b/src/main/java/com/cmcc/simulator/xml/SN.java @@ -0,0 +1,39 @@ +package com.cmcc.simulator.xml; + +import javax.xml.bind.annotation.XmlElement; + +public class SN { + + private String sn; + private int sv; + + public SN() { + super(); + // TODO Auto-generated constructor stub + } + + public SN(String sn, int sv) { + super(); + this.sn = sn; + this.sv = sv; + } + + @XmlElement(name = "SN") + public String getSn() { + return sn; + } + + public void setSn(String sn) { + this.sn = sn; + } + + @XmlElement(name = "SV") + public int getSv() { + return sv; + } + + public void setSv(int sv) { + this.sv = sv; + } + +} diff --git a/src/main/java/com/cmcc/simulator/xml/Utils.java b/src/main/java/com/cmcc/simulator/xml/Utils.java new file mode 100644 index 0000000..747420a --- /dev/null +++ b/src/main/java/com/cmcc/simulator/xml/Utils.java @@ -0,0 +1,129 @@ +package com.cmcc.simulator.xml; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.StringWriter; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; + +public class Utils { + + public static String beanToXml(Object obj, Class<?> load) throws JAXBException { + JAXBContext context = JAXBContext.newInstance(load); + Marshaller marshaller = context.createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + marshaller.setProperty(Marshaller.JAXB_ENCODING, "utf-8"); + StringWriter writer = new StringWriter(); + marshaller.marshal(obj, writer); + return writer.toString(); + } + + public static void writeToFile(String outputFilePath, String content) { + File file = new File(outputFilePath); + try { + FileWriter writer = new FileWriter(file); + writer.write(content); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static String createAmfFile(List<Instance> objects) throws JAXBException { + + FileHeader fileHeader = new FileHeader(); + fileHeader.setElementType("AMF"); + fileHeader.setPmVersion("V0.4.0"); + fileHeader.setTimeZone("UTC+8"); + fileHeader.setVendorName("CMCC"); + fileHeader.setPeriod(15); + fileHeader.setStartTime(Utils.getTimeShort()); + fileHeader.setTimeStamp(Utils.getTimeShort()); + + Measurements measurements = new Measurements(); + PmData pmData = new PmData(objects); + N n46 = new N("46", "AMF.RegSub._NS"); + List<N> ns = new ArrayList<>(); + ns.add(n46); + measurements.setN(ns); + measurements.setObjectType("AmfFunction"); + measurements.setPmData(pmData); + + PmFile pmFile = new PmFile(fileHeader, measurements); + String str = Utils.beanToXml(pmFile, PmFile.class); + + str = str.replaceAll("<sns>", ""); + str = str.replaceAll("</sns>", ""); + str = str.replaceAll("((\r\n)|\n)[\\s\t ]*(\\1)+", "$1").replaceAll("^((\r\n)|\n)", ""); + return str; + + } + + public static String createUPFFile(List<Instance> objects) throws Exception { + FileHeader fileHeader = new FileHeader(); + fileHeader.setElementType("UPF"); + fileHeader.setPmVersion("V0.4.0"); + fileHeader.setTimeZone("UTC+8"); + fileHeader.setVendorName("CMCC"); + fileHeader.setPeriod(15); + fileHeader.setStartTime(Utils.getTimeShort()); + fileHeader.setTimeStamp(Utils.getTimeShort()); + + Measurements measurements = new Measurements(); + PmData pmData = new PmData(objects); + N n9 = new N("9", "UPF.N3IncPkt._Dnn"); + N n11 = new N("11", "UPF.N3OgPkt._Dnn"); + List<N> ns = new ArrayList<>(); + ns.add(n9); + ns.add(n11); + measurements.setN(ns); + measurements.setObjectType("UpfFunction"); + measurements.setPmData(pmData); + + PmFile pmFile = new PmFile(fileHeader, measurements); + String str = Utils.beanToXml(pmFile, PmFile.class); + + str = str.replaceAll("<sns>", ""); + str = str.replaceAll("</sns>", ""); + str = str.replaceAll("((\r\n)|\n)[\\s\t ]*(\\1)+", "$1").replaceAll("^((\r\n)|\n)", ""); + return str; + + } + + public static boolean delFile(File file) { + if (!file.exists()) { + return false; + } + + if (file.isDirectory()) { + File[] files = file.listFiles(); + for (File f : files) { + delFile(f); + } + } + return file.delete(); + } + + + public static String getTimeShort() { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); + Date currentTime = new Date(); + String dateString = formatter.format(currentTime); + return dateString; + } + + public static String getTimeFormat() { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date currentTime = new Date(); + String dateString = formatter.format(currentTime); + return dateString; + } + +}
\ No newline at end of file diff --git a/src/main/java/com/cmcc/simulator/xml/V.java b/src/main/java/com/cmcc/simulator/xml/V.java new file mode 100644 index 0000000..a51672e --- /dev/null +++ b/src/main/java/com/cmcc/simulator/xml/V.java @@ -0,0 +1,38 @@ +package com.cmcc.simulator.xml; + +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlValue; + +public class V { + String v; + int value; + + public V() { + super(); + } + + public V(String i, int value) { + super(); + this.v = i; + this.value = value; + } + + @XmlAttribute(name = "i") + public String getV() { + return v; + } + + public void setV(String v) { + this.v = v; + } + + public int getValue() { + return value; + } + + @XmlValue + public void setValue(int value) { + this.value = value; + } + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..96c5b9b --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,17 @@ +server.port=10000 +logging.file=/root/luk/simulator/log +snssaipath=/root/luk/simulator/snssai.json +filepath=/home/ubuntu/dcae +notifyurl=http://192.168.235.34:80/v1/pm/notification +amffilepath=/home/ubuntu/dcae/AMF.xml.gz +upffilepath=/home/ubuntu/dcae/UPF.xml.gz +fixeddelay=900000 +ftppath=sftp://ubuntu:root123@192.168.235.34:22/dcae/PM.tar.gz +spring.jackson.default-property-inclusion=NON_NULL +#logging.path=/home/ubuntu/dcae/ +#logging.file=simulator.log + +server.ssl.key-store=luk.keystore +server.ssl.key-store-password=tomcat +server.ssl.keyStoreType=JKS +server.ssl.keyAlias:luk
\ No newline at end of file |