Skip to content

Commit db991dd

Browse files
author
Murali Reddy
committed
NAAS : adding support for service capabilities to be specified as part of network offering
1 parent eac54e3 commit db991dd

16 files changed

Lines changed: 199 additions & 15 deletions

‎api/src/com/cloud/api/ApiConstants.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ public class ApiConstants {
274274
public static final String FIREWALL_SERVICE = "firewallservice";
275275
public static final String GATEWAY_SERVICE = "gatewayservice";
276276
public static final String SERVICE_PROVIDER_LIST = "serviceproviderlist";
277+
public static final String SERVICE_CAPABILITY_LIST = "servicecapabilitylist";
277278
public static final String PROVIDER = "provider";
278279
public static final String NETWORK_SPEED = "networkspeed";
279280
public static final String BROADCAST_DOMAIN_RANGE = "broadcastdomainrange";

‎api/src/com/cloud/api/commands/CreateNetworkOfferingCmd.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import com.cloud.api.Parameter;
3434
import com.cloud.api.ServerApiException;
3535
import com.cloud.api.response.NetworkOfferingResponse;
36+
import com.cloud.network.Network.Capability;
37+
import com.cloud.network.Network.Service;
3638
import com.cloud.offering.NetworkOffering;
3739
import com.cloud.offering.NetworkOffering.Availability;
3840
import com.cloud.user.Account;
@@ -112,6 +114,9 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
112114
@Parameter(name = ApiConstants.SERVICE_PROVIDER_LIST, type = CommandType.MAP, description = "provider to service mapping. If not specified, the provider for the service will be mapped to the default provider on the physical network")
113115
private Map serviceProviderList;
114116

117+
@Parameter(name = ApiConstants.SERVICE_CAPABILITY_LIST, type = CommandType.MAP, description = "desired service capabilities as part of network offering")
118+
private Map serviceCapabilistList;
119+
115120
/////////////////////////////////////////////////////
116121
/////////////////// Accessors ///////////////////////
117122
/////////////////////////////////////////////////////
@@ -232,6 +237,17 @@ public Map<String, List<String>> getServiceProviders() {
232237
return serviceProviderMap;
233238
}
234239

240+
public Map<Capability, String> getServiceCapabilities(Service service) {
241+
242+
Map<Capability, String> serviceCapabilityMap = null;
243+
if (serviceCapabilistList != null && !serviceCapabilistList.isEmpty()) {
244+
if (serviceCapabilistList.containsKey(service.getName())) {
245+
serviceCapabilityMap = (HashMap<Capability, String>) serviceCapabilistList.get(service.getName());
246+
}
247+
}
248+
return serviceCapabilityMap;
249+
}
250+
235251
/////////////////////////////////////////////////////
236252
/////////////// API Implementation///////////////////
237253
/////////////////////////////////////////////////////

‎api/src/com/cloud/api/commands/UpdateNetworkOfferingCmd.java‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import com.cloud.api.Parameter;
3434
import com.cloud.api.ServerApiException;
3535
import com.cloud.api.response.NetworkOfferingResponse;
36+
import com.cloud.network.Network.Capability;
37+
import com.cloud.network.Network.Service;
3638
import com.cloud.offering.NetworkOffering;
3739
import com.cloud.user.Account;
3840

@@ -92,7 +94,10 @@ public class UpdateNetworkOfferingCmd extends BaseCmd {
9294

9395
@Parameter(name = ApiConstants.SERVICE_PROVIDER_LIST, type = CommandType.MAP, description = "provider to service mapping. If not specified, the provider for the service will be mapped to the default provider on the physical network")
9496
private Map serviceProviderList;
95-
97+
98+
@Parameter(name = ApiConstants.SERVICE_CAPABILITY_LIST, type = CommandType.MAP, description = "desired service capabilities as part of network offering")
99+
private Map serviceCapabilistList;
100+
96101
@Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="update state for the network offering")
97102
private String state;
98103

@@ -184,6 +189,18 @@ public Map<String, List<String>> getServiceProviders() {
184189
return serviceProviderMap;
185190
}
186191

192+
public Map<Capability, String> getServiceCapabilities(Service service) {
193+
194+
Map<Capability, String> serviceCapabilityMap = null;
195+
if (serviceCapabilistList != null && !serviceCapabilistList.isEmpty()) {
196+
if (serviceCapabilistList.containsKey(service.getName())) {
197+
serviceCapabilityMap = (HashMap<Capability, String>) serviceCapabilistList.get(service.getName());
198+
}
199+
}
200+
return serviceCapabilityMap;
201+
}
202+
203+
187204
public String getState() {
188205
return state;
189206
}

‎api/src/com/cloud/api/response/NetworkOfferingResponse.java‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,13 @@ public class NetworkOfferingResponse extends BaseResponse{
6868

6969
@SerializedName("service") @Param(description="the list of supported services", responseObject = ServiceResponse.class)
7070
private List<ServiceResponse> services;
71-
71+
72+
@SerializedName(ApiConstants.IS_SHARED) @Param(description="true if load balncer service offered is shared by multiple networks", responseObject = ServiceResponse.class)
73+
private Boolean isLbShared;
74+
75+
@SerializedName(ApiConstants.IS_SHARED) @Param(description="true if soruce NAT service offered is shared by multiple networks", responseObject = ServiceResponse.class)
76+
private Boolean isSourceNatShared;
77+
7278
public void setId(Long id) {
7379
this.id = id;
7480
}
@@ -128,4 +134,12 @@ public void setState(String state) {
128134
public void setGuestIpType(String type) {
129135
this.guestIpType = type;
130136
}
137+
138+
public void setIsLBShared(boolean isLbSared) {
139+
this.isLbShared = isLbSared;
140+
}
141+
142+
public void setIsSourceNatShared(boolean isSourceNatShared) {
143+
this.isSourceNatShared = isSourceNatShared;
144+
}
131145
}

‎api/src/com/cloud/network/Network.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static class Service {
5252
public static final Service Dns = new Service("Dns", Capability.AllowDnsSuffixModification);
5353
public static final Service Gateway = new Service("Gateway");
5454
public static final Service Firewall = new Service("Firewall", Capability.SupportedProtocols, Capability.MultipleIps, Capability.SupportedSourceNatTypes, Capability.TrafficStatistics);
55-
public static final Service Lb = new Service("Lb", Capability.SupportedLBAlgorithms, Capability.SupportedProtocols, Capability.TrafficStatistics, Capability.LoadBalancingSupportedIps);
55+
public static final Service Lb = new Service("Lb", Capability.SupportedLBAlgorithms, Capability.SupportedLBIsolation, Capability.SupportedProtocols, Capability.TrafficStatistics, Capability.LoadBalancingSupportedIps);
5656
public static final Service UserData = new Service("UserData");
5757
public static final Service SourceNat = new Service("SourceNat");
5858
public static final Service StaticNat = new Service("StaticNat");
@@ -156,6 +156,7 @@ public static class Capability {
156156

157157
public static final Capability SupportedProtocols = new Capability("SupportedProtocols");
158158
public static final Capability SupportedLBAlgorithms = new Capability("SupportedLbAlgorithms");
159+
public static final Capability SupportedLBIsolation = new Capability("SupportedLBIsolation");
159160
public static final Capability MultipleIps = new Capability("MultipleIps");
160161
public static final Capability SupportedSourceNatTypes = new Capability("SupportedSourceNatTypes");
161162
public static final Capability SupportedVpnTypes = new Capability("SupportedVpnTypes");

‎api/src/com/cloud/offering/NetworkOffering.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,8 @@ public enum State {
9696
GuestType getGuestType();
9797

9898
Long getServiceOfferingId();
99+
100+
boolean getDedicatedLB();
101+
102+
boolean getSharedSourceNat();
99103
}

‎server/src/com/cloud/api/ApiResponseHelper.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,6 +2113,8 @@ public NetworkOfferingResponse createNetworkOfferingResponse(NetworkOffering off
21132113
response.setSpecifyVlan(offering.getSpecifyVlan());
21142114
response.setAvailability(offering.getAvailability().toString());
21152115
response.setNetworkRate(ApiDBUtils.getNetworkRate(offering.getId()));
2116+
response.setIsLBShared(!offering.getDedicatedLB());
2117+
response.setIsSourceNatShared(offering.getSharedSourceNat());
21162118
if (offering.getGuestType() != null) {
21172119
response.setGuestIpType(offering.getGuestType().toString());
21182120
}

‎server/src/com/cloud/configuration/ConfigurationManager.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.cloud.exception.InvalidParameterValueException;
3434
import com.cloud.exception.PermissionDeniedException;
3535
import com.cloud.network.Network;
36+
import com.cloud.network.Network.Capability;
3637
import com.cloud.network.Network.Provider;
3738
import com.cloud.network.Network.Service;
3839
import com.cloud.network.Networks.TrafficType;
@@ -186,8 +187,9 @@ void checkDiskOfferingAccess(Account caller, DiskOffering dof)
186187
* @return network offering object
187188
*/
188189

189-
NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, Availability availability, Integer networkRate, Map<Service, Set<Provider>> serviceProviderMap, boolean isDefault, Network.GuestType type, boolean systemOnly, Long serviceOfferingId);
190-
190+
NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, Availability availability, Integer networkRate, Map<Service, Set<Provider>> serviceProviderMap, boolean isDefault, Network.GuestType type, boolean systemOnly, Long serviceOfferingId,
191+
Map<Capability, String> lbServiceCapabilityMap, Map<Capability, String> fwServiceCapabilityMap);
192+
191193
Vlan createVlanAndPublicIpRange(Long userId, Long zoneId, Long podId, String startIP, String endIP, String vlanGateway, String vlanNetmask, boolean forVirtualNetwork, String vlanId, Account account, Long networkId, Long physicalNetworkId) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException;
192194

193195
void createDefaultNetworks(long zoneId, boolean isSecurityGroupEnabled, long physicalNetworkId) throws ConcurrentOperationException;

‎server/src/com/cloud/configuration/ConfigurationManagerImpl.java‎

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
import com.cloud.host.dao.HostDetailsDao;
9797
import com.cloud.hypervisor.Hypervisor.HypervisorType;
9898
import com.cloud.network.Network;
99+
import com.cloud.network.Network.Capability;
99100
import com.cloud.network.Network.GuestType;
100101
import com.cloud.network.Network.Provider;
101102
import com.cloud.network.Network.Service;
@@ -2968,19 +2969,73 @@ public NetworkOffering createNetworkOffering(CreateNetworkOfferingCmd cmd) {
29682969
}
29692970
}
29702971

2971-
return createNetworkOffering(userId, name, displayText, trafficType, tags, maxConnections, specifyVlan, availability, networkRate, serviceProviderMap, false, guestType, false, serviceOfferingId);
2972+
// verify the LB service capabilities specified in the network offering
2973+
Map<Capability, String> lbServiceCapabilityMap = cmd.getServiceCapabilities(Service.Lb);
2974+
if (!cmd.getLbService() && lbServiceCapabilityMap != null && !lbServiceCapabilityMap.isEmpty()) {
2975+
throw new InvalidParameterValueException("Capabilities for LB service can be specifed only when LB service is enabled for network offering.");
2976+
}
2977+
validateLoadBalancerServiceCapabilities(lbServiceCapabilityMap);
2978+
2979+
// verify the Firewall service capabilities specified in the network offering
2980+
Map<Capability, String> fwServiceCapabilityMap = cmd.getServiceCapabilities(Service.Firewall);
2981+
if (!cmd.getFirewallService() && fwServiceCapabilityMap != null && !fwServiceCapabilityMap.isEmpty()) {
2982+
throw new InvalidParameterValueException("Capabilities for Firewall service can be specifed only when Firewall service is enabled for network offering.");
2983+
}
2984+
validateFirewallServiceCapablities(fwServiceCapabilityMap);
2985+
2986+
return createNetworkOffering(userId, name, displayText, trafficType, tags, maxConnections, specifyVlan, availability, networkRate, serviceProviderMap, false,
2987+
guestType, false, serviceOfferingId, lbServiceCapabilityMap, fwServiceCapabilityMap);
2988+
}
2989+
2990+
void validateLoadBalancerServiceCapabilities(Map<Capability, String> lbServiceCapabilityMap) {
2991+
if ((lbServiceCapabilityMap != null) && (lbServiceCapabilityMap.keySet().size() > 1 || !lbServiceCapabilityMap.containsKey(Capability.SupportedLBIsolation.getName()))) {
2992+
throw new InvalidParameterValueException("Only Load balancer isolation capability can be sepcified for LB service");
2993+
} else {
2994+
String isolationCapability = lbServiceCapabilityMap.get(Capability.SupportedLBIsolation.getName());
2995+
boolean dedicatedLb = isolationCapability.contains("dedicated");
2996+
boolean sharedLB = isolationCapability.contains("shared");
2997+
if ((dedicatedLb && sharedLB) || (!dedicatedLb && !sharedLB)){
2998+
throw new InvalidParameterValueException("Either dedicated or shared isolation can be specified for " + Capability.SupportedLBIsolation.getName());
2999+
}
3000+
}
29723001
}
29733002

3003+
void validateFirewallServiceCapablities(Map<Capability, String> fwServiceCapabilityMap) {
3004+
if ((fwServiceCapabilityMap != null) && (fwServiceCapabilityMap.keySet().size() > 1) || !fwServiceCapabilityMap.containsKey(Capability.SupportedSourceNatTypes.getName())) {
3005+
throw new InvalidParameterValueException("Only Supported Source NAT type capability can be sepcified for firewall service");
3006+
} else {
3007+
String sourceNatType = fwServiceCapabilityMap.get(Capability.SupportedSourceNatTypes.getName());
3008+
boolean perAccount = sourceNatType.contains("peraccount");
3009+
boolean perZone = sourceNatType.contains("perzone");
3010+
if ((perAccount && perZone) || (!perAccount && !perZone)) {
3011+
throw new InvalidParameterValueException("Either perAccount or perZone source NAT type can be specified for " + Capability.SupportedSourceNatTypes.getName());
3012+
}
3013+
}
3014+
}
3015+
29743016
@Override
29753017
@DB
29763018
public NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan,
2977-
Availability availability, Integer networkRate, Map<Service, Set<Provider>> serviceProviderMap, boolean isDefault, Network.GuestType type, boolean systemOnly, Long serviceOfferingId) {
3019+
Availability availability, Integer networkRate, Map<Service, Set<Provider>> serviceProviderMap, boolean isDefault, Network.GuestType type,
3020+
boolean systemOnly, Long serviceOfferingId, Map<Capability, String> lbServiceCapabilityMap, Map<Capability, String> fwServiceCapabilityMap) {
29783021

29793022
String multicastRateStr = _configDao.getValue("multicast.throttling.rate");
29803023
int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr));
29813024
tags = cleanupTags(tags);
29823025

2983-
NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan, networkRate, multicastRate, maxConnections, isDefault, availability, tags, type);
3026+
boolean dedicatedLb = true;
3027+
if ((lbServiceCapabilityMap != null) && (!lbServiceCapabilityMap.isEmpty())) {
3028+
String isolationCapability = lbServiceCapabilityMap.get(Capability.SupportedLBIsolation);
3029+
dedicatedLb = isolationCapability.contains("dedicated");
3030+
}
3031+
3032+
boolean sharedSourceNat = false;
3033+
if ((fwServiceCapabilityMap != null) && (!fwServiceCapabilityMap.isEmpty())) {
3034+
String sourceNatType = fwServiceCapabilityMap.get(Capability.SupportedSourceNatTypes.getName());
3035+
sharedSourceNat = sourceNatType.contains("perzone");
3036+
}
3037+
3038+
NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan, networkRate, multicastRate, maxConnections, isDefault, availability, tags, type, dedicatedLb, sharedSourceNat);
29843039

29853040
if (serviceOfferingId != null) {
29863041
offering.setServiceOfferingId(serviceOfferingId);
@@ -3318,6 +3373,35 @@ public NetworkOffering updateNetworkOffering(UpdateNetworkOfferingCmd cmd) {
33183373
}
33193374
}
33203375

3376+
// verify and update the LB service capabilities specified in the network offering
3377+
Map<Capability, String> lbServiceCapabilityMap = cmd.getServiceCapabilities(Service.Lb);
3378+
boolean dedicatedLb = true;
3379+
if (!cmd.getLbService() && lbServiceCapabilityMap != null && !lbServiceCapabilityMap.isEmpty()) {
3380+
throw new InvalidParameterValueException("Capabilities for LB service can be specifed only when LB service is enabled for network offering.");
3381+
}
3382+
validateLoadBalancerServiceCapabilities(lbServiceCapabilityMap);
3383+
3384+
if ((lbServiceCapabilityMap != null) && (!lbServiceCapabilityMap.isEmpty())) {
3385+
String isolationCapability = lbServiceCapabilityMap.get(Capability.SupportedLBIsolation);
3386+
dedicatedLb = isolationCapability.contains("dedicated");
3387+
}
3388+
offering.setDedicatedLb(dedicatedLb);
3389+
3390+
// verify the Firewall service capabilities specified in the network offering
3391+
Map<Capability, String> fwServiceCapabilityMap = cmd.getServiceCapabilities(Service.Firewall);
3392+
boolean sharedSourceNat = false;
3393+
3394+
if (!cmd.getFirewallService() && fwServiceCapabilityMap != null && !fwServiceCapabilityMap.isEmpty()) {
3395+
throw new InvalidParameterValueException("Capabilities for Firewall service can be specifed only when Firewall service is enabled for network offering.");
3396+
}
3397+
validateFirewallServiceCapablities(fwServiceCapabilityMap);
3398+
3399+
if ((fwServiceCapabilityMap != null) && (!fwServiceCapabilityMap.isEmpty())) {
3400+
String sourceNatType = fwServiceCapabilityMap.get(Capability.SupportedSourceNatTypes.getName());
3401+
sharedSourceNat = sourceNatType.contains("perzone");
3402+
}
3403+
offering.setSharedSourceNat(sharedSourceNat);
3404+
33213405
if (svcPrv != null && !svcPrv.isEmpty()) {
33223406
if (networksExist) {
33233407
throw new InvalidParameterValueException("Unable to reset service providers as there are existing networks using this network offering");

0 commit comments

Comments
 (0)