From c4c99f0d6cb5eeb7475ccac5c00c960b1d8f83ed Mon Sep 17 00:00:00 2001 From: Vidyashree Rama Date: Tue, 2 Apr 2019 14:40:35 +0530 Subject: Add CCVPN Bandwidth on demand policy CCVPN Bandwidth on demand policy Issue-ID: POLICY-1405 Change-Id: I67bceb35e5a849933b3e46772c9cbbbaab1e9a75 Signed-off-by: Vidyashree Rama --- .../actor/sdnc/SdncActorServiceProvider.java | 84 +++++++++++++++++++--- .../actor/sdnc/SdncActorServiceProviderTest.java | 19 ++--- 2 files changed, 85 insertions(+), 18 deletions(-) (limited to 'controlloop/common/actors') diff --git a/controlloop/common/actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProvider.java b/controlloop/common/actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProvider.java index b9eaf7ed4..ab6a77813 100644 --- a/controlloop/common/actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProvider.java +++ b/controlloop/common/actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProvider.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * SdncActorServiceProvider * ================================================================================ - * Copyright (C) 2018 Huawei Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 Huawei Technologies Co., Ltd. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,6 +37,11 @@ import org.onap.policy.sdnc.SdncHealRequest; import org.onap.policy.sdnc.SdncHealRequestHeaderInfo; import org.onap.policy.sdnc.SdncHealRequestInfo; import org.onap.policy.sdnc.SdncHealServiceInfo; +import org.onap.policy.sdnc.SdncHealVfModuleParameter; +import org.onap.policy.sdnc.SdncHealVfModuleParametersInfo; +import org.onap.policy.sdnc.SdncHealVfModuleRequestInput; +import org.onap.policy.sdnc.SdncHealVnfInfo; + import org.onap.policy.sdnc.SdncRequest; import org.slf4j.Logger; @@ -55,6 +60,9 @@ public class SdncActorServiceProvider implements Actor { // Strings for recipes private static final String RECIPE_REROUTE = "Reroute"; + // Strings for recipes + private static final String RECIPE_BW_ON_DEMAND = "BandwidthOnDemand"; + private static final ImmutableList recipes = ImmutableList.of(RECIPE_REROUTE); private static final ImmutableMap> targets = new ImmutableMap.Builder>().put(RECIPE_REROUTE, ImmutableList.of(TARGET_VM)).build(); @@ -81,34 +89,92 @@ public class SdncActorServiceProvider implements Actor { /** * Construct a request. - * + * * @param onset the onset event * @param operation the control loop operation * @param policy the policy * @return the constructed request */ - public static SdncRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, + public SdncRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, Policy policy) { + switch (policy.getRecipe()) { + case RECIPE_REROUTE: + return constructReOptimizeRequest(onset); + case RECIPE_BW_ON_DEMAND: + logger.info("Construct request for receipe {}" , RECIPE_BW_ON_DEMAND); + return constructBwOnDemandRequest(onset); + default: + logger.info("Unsupported recipe {} " + policy.getRecipe()); + return null; + } + } - if (!policy.getRecipe().equalsIgnoreCase(RECIPE_REROUTE)) { + private SdncRequest constructBwOnDemandRequest(VirtualControlLoopEvent onset) { + // Construct an Sdnc request + String serviceInstance = onset.getAai().get("service-instance.service-instance-id"); + if (serviceInstance == null || serviceInstance.isEmpty()) { + // This indicates that AAI Enrichment needs to be done by event producer. return null; } + SdncHealVfModuleParameter bandwidth = new SdncHealVfModuleParameter(); + bandwidth.setName("bandwidth"); + bandwidth.setValue(onset.getAai().get("bandwidth")); + + SdncHealVfModuleParameter timeStamp = new SdncHealVfModuleParameter(); + timeStamp.setName("bandwidth-change-time"); + timeStamp.setValue(onset.getAai().get("bandwidth-change-time")); + + SdncHealVfModuleParametersInfo vfParametersInfo = new SdncHealVfModuleParametersInfo(); + vfParametersInfo.addParameters(bandwidth); + vfParametersInfo.addParameters(timeStamp); + + SdncHealVfModuleRequestInput vfRequestInfo = new SdncHealVfModuleRequestInput(); + vfRequestInfo.setVfModuleParametersInfo(vfParametersInfo); + + SdncHealServiceInfo serviceInfo = new SdncHealServiceInfo(); + serviceInfo.setServiceInstanceId(serviceInstance); + + SdncHealRequestInfo requestInfo = new SdncHealRequestInfo(); + requestInfo.setRequestAction("SdwanBWPolicyChange"); + + SdncHealRequestHeaderInfo headerInfo = new SdncHealRequestHeaderInfo(); + headerInfo.setSvcAction("update"); + headerInfo.setSvcRequestId(UUID.randomUUID().toString()); + SdncRequest request = new SdncRequest(); + request.setNsInstanceId(serviceInstance); + request.setRequestId(onset.getRequestId()); + request.setUrl("/GENERIC-RESOURCE-API:vnf-topology-operation"); + + SdncHealVnfInfo vnfInfo = new SdncHealVnfInfo(); + vnfInfo.setVnfId(onset.getAai().get("vnfId")); + + SdncHealRequest healRequest = new SdncHealRequest(); + healRequest.setVnfInfo(vnfInfo); + healRequest.setRequestHeaderInfo(headerInfo); + healRequest.setVfModuleRequestInput(vfRequestInfo); + healRequest.setRequestInfo(requestInfo); + healRequest.setServiceInfo(serviceInfo); + request.setHealRequest(healRequest); + return request; + } + + private SdncRequest constructReOptimizeRequest(VirtualControlLoopEvent onset) { // Construct an Sdnc request String serviceInstance = onset.getAai().get("service-instance.service-instance-id"); if (serviceInstance == null || serviceInstance.isEmpty()) { - // This indicates that AAI Enrichment needs to be done by event producer. + // This indicates that AAI Enrichment needs to be done by event producer. return null; } SdncHealServiceInfo serviceInfo = new SdncHealServiceInfo(); serviceInfo.setServiceInstanceId(serviceInstance); - + String networkId = onset.getAai().get("network-information.network-id"); if (networkId == null || networkId.isEmpty()) { - // This indicates that AAI Enrichment needs to be done by event producer. + // This indicates that AAI Enrichment needs to be done by event producer. return null; } - SdncHealNetworkInfo networkInfo = new SdncHealNetworkInfo(); + SdncHealNetworkInfo networkInfo = new SdncHealNetworkInfo(); networkInfo.setNetworkId(networkId); SdncHealRequestInfo requestInfo = new SdncHealRequestInfo(); @@ -121,6 +187,7 @@ public class SdncActorServiceProvider implements Actor { SdncRequest request = new SdncRequest(); request.setNsInstanceId(serviceInstance); request.setRequestId(onset.getRequestId()); + request.setUrl("/GENERIC-RESOURCE-API:network-topology-operation"); SdncHealRequest healRequest = new SdncHealRequest(); healRequest.setRequestHeaderInfo(headerInfo); @@ -128,7 +195,6 @@ public class SdncActorServiceProvider implements Actor { healRequest.setRequestInfo(requestInfo); healRequest.setServiceInfo(serviceInfo); request.setHealRequest(healRequest); - return request; } } \ No newline at end of file diff --git a/controlloop/common/actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProviderTest.java b/controlloop/common/actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProviderTest.java index 633234f44..f968f8609 100644 --- a/controlloop/common/actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProviderTest.java +++ b/controlloop/common/actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProviderTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * TestSdncActorServiceProvider * ================================================================================ - * Copyright (C) 2018 Huawei. All rights reserved. + * Copyright (C) 2018-2019 Huawei Technologies Co., Ltd. All rights reserved. * Modifications Copyright (C) 2018 AT&T Corp. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -68,31 +68,32 @@ public class SdncActorServiceProviderTest { Policy policy = new Policy(); policy.setRecipe("Reroute"); - assertNull(SdncActorServiceProvider.constructRequest(onset, operation, policy)); + SdncActorServiceProvider provider = new SdncActorServiceProvider(); + assertNull(provider.constructRequest(onset, operation, policy)); onset.getAai().put("network-information.network-id", "network-5555"); - assertNull(SdncActorServiceProvider.constructRequest(onset, operation, policy)); + assertNull(provider.constructRequest(onset, operation, policy)); PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666"); PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI"); PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI"); - assertNull(SdncActorServiceProvider.constructRequest(onset, operation, policy)); + assertNull(provider.constructRequest(onset, operation, policy)); UUID requestId = UUID.randomUUID(); onset.setRequestId(requestId); - assertNull(SdncActorServiceProvider.constructRequest(onset, operation, policy)); + assertNull(provider.constructRequest(onset, operation, policy)); PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI"); - assertNull(SdncActorServiceProvider.constructRequest(onset, operation, policy)); + assertNull(provider.constructRequest(onset, operation, policy)); onset.getAai().put("service-instance.service-instance-id", "service-instance-01"); - assertNotNull(SdncActorServiceProvider.constructRequest(onset, operation, policy)); + assertNotNull(provider.constructRequest(onset, operation, policy)); policy.setRecipe("Reroute"); - assertNotNull(SdncActorServiceProvider.constructRequest(onset, operation, policy)); + assertNotNull(provider.constructRequest(onset, operation, policy)); SdncRequest request = - SdncActorServiceProvider.constructRequest(onset, operation, policy); + provider.constructRequest(onset, operation, policy); assertEquals(requestId, Objects.requireNonNull(request).getRequestId()); assertEquals("reoptimize", request.getHealRequest().getRequestHeaderInfo().getSvcAction()); -- cgit 1.2.3-korg