Skip to content

Commit 177e157

Browse files
author
Sheng Yang
committed
CLOUDSTACK-306: Move inline mode parameter from device to network offering
One F5 device can be used as inline and side-by-side at the same time(for different networks). So we can define inline or not on network base.
1 parent 717f9dc commit 177e157

22 files changed

Lines changed: 131 additions & 117 deletions

File tree

api/src/com/cloud/agent/api/to/LoadBalancerTO.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,13 @@ public class LoadBalancerTO {
4343
String algorithm;
4444
boolean revoked;
4545
boolean alreadyAdded;
46+
boolean inline;
4647
DestinationTO[] destinations;
4748
private StickinessPolicyTO[] stickinessPolicies;
4849
private AutoScaleVmGroupTO autoScaleVmGroupTO;
4950
final static int MAX_STICKINESS_POLICIES = 1;
5051

51-
public LoadBalancerTO(String uuid, String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, List<LbDestination> destinations) {
52+
public LoadBalancerTO(String uuid, String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, boolean inline, List<LbDestination> destinations) {
5253
if (destinations == null) { // for autoscaleconfig destinations will be null;
5354
destinations = new ArrayList<LbDestination>();
5455
}
@@ -59,6 +60,7 @@ public LoadBalancerTO(String uuid, String srcIp, int srcPort, String protocol, S
5960
this.algorithm = algorithm;
6061
this.revoked = revoked;
6162
this.alreadyAdded = alreadyAdded;
63+
this.inline = inline;
6264
this.destinations = new DestinationTO[destinations.size()];
6365
this.stickinessPolicies = null;
6466
int i = 0;
@@ -67,8 +69,8 @@ public LoadBalancerTO(String uuid, String srcIp, int srcPort, String protocol, S
6769
}
6870
}
6971

70-
public LoadBalancerTO(String id, String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, List<LbDestination> arg_destinations, List<LbStickinessPolicy> stickinessPolicies) {
71-
this(id, srcIp, srcPort, protocol, algorithm, revoked, alreadyAdded, arg_destinations);
72+
public LoadBalancerTO(String id, String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, boolean inline, List<LbDestination> arg_destinations, List<LbStickinessPolicy> stickinessPolicies) {
73+
this(id, srcIp, srcPort, protocol, algorithm, revoked, alreadyAdded, inline, arg_destinations);
7274
this.stickinessPolicies = null;
7375
if (stickinessPolicies != null && stickinessPolicies.size() > 0) {
7476
this.stickinessPolicies = new StickinessPolicyTO[MAX_STICKINESS_POLICIES];
@@ -116,6 +118,10 @@ public boolean isAlreadyAdded() {
116118
return alreadyAdded;
117119
}
118120

121+
public boolean isInline() {
122+
return inline;
123+
}
124+
119125
public StickinessPolicyTO[] getStickinessPolicies() {
120126
return stickinessPolicies;
121127
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ public static class Capability {
171171
public static final Capability AssociatePublicIP = new Capability("AssociatePublicIP");
172172
public static final Capability ElasticLb = new Capability("ElasticLb");
173173
public static final Capability AutoScaleCounters = new Capability("AutoScaleCounters");
174+
public static final Capability InlineMode = new Capability("InlineMode");
174175

175176
private String name;
176177

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,5 @@ public enum State {
111111

112112
boolean getSpecifyIpRanges();
113113

114+
boolean isInline();
114115
}

plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ private void createApplyLoadBalancingRulesCommands(
296296
int srcPort = rule.getSourcePortStart();
297297
String uuid = rule.getUuid();
298298
List<LbDestination> destinations = rule.getDestinations();
299-
LoadBalancerTO lb = new LoadBalancerTO(uuid, elbIp, srcPort, protocol, algorithm, revoked, false, destinations);
299+
LoadBalancerTO lb = new LoadBalancerTO(uuid, elbIp, srcPort, protocol, algorithm, revoked, false, false, destinations);
300300
lbs[i++] = lb;
301301
}
302302

plugins/network-elements/f5/src/com/cloud/api/response/F5LoadBalancerResponse.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ public class F5LoadBalancerResponse extends BaseResponse {
4343
@SerializedName(ApiConstants.LOAD_BALANCER_DEVICE_DEDICATED) @Param(description="true if device is dedicated for an account")
4444
private Boolean dedicatedLoadBalancer;
4545

46-
@SerializedName(ApiConstants.INLINE) @Param(description="true if device is inline with firewall device")
47-
private Boolean inlineLoadBalancer;
48-
4946
@SerializedName(ApiConstants.PUBLIC_INTERFACE) @Param(description="the public interface of the load balancer")
5047
private String publicInterface;
5148

@@ -83,10 +80,6 @@ public void setDedicatedLoadBalancer(boolean isDedicated) {
8380
this.dedicatedLoadBalancer = isDedicated;
8481
}
8582

86-
public void setInlineMode(boolean inline) {
87-
this.inlineLoadBalancer = inline;
88-
}
89-
9083
public void setPublicInterface(String publicInterface) {
9184
this.publicInterface = publicInterface;
9285
}

plugins/network-elements/f5/src/com/cloud/network/element/F5ExternalLoadBalancerElement.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ public Map<Service, Map<Capability, String>> getCapabilities() {
206206
// Specifies that load balancing rules can only be made with public IPs that aren't source NAT IPs
207207
lbCapabilities.put(Capability.LoadBalancingSupportedIps, "additional");
208208

209+
// Support inline mode with firewall
210+
lbCapabilities.put(Capability.InlineMode, "true");
211+
209212
LbStickinessMethod method;
210213
List<LbStickinessMethod> methodList = new ArrayList<LbStickinessMethod>();
211214
method = new LbStickinessMethod(StickinessMethodType.LBCookieBased, "This is cookie based sticky method, can be used only for http");
@@ -448,7 +451,6 @@ public F5LoadBalancerResponse createF5LoadBalancerResponse(ExternalLoadBalancerD
448451
} else {
449452
response.setDeviceCapacity(lbDeviceVO.getCapacity());
450453
}
451-
response.setInlineMode(lbDeviceVO.getIsInLineMode());
452454
response.setDedicatedLoadBalancer(lbDeviceVO.getIsDedicatedDevice());
453455
response.setProvider(lbDeviceVO.getProviderName());
454456
response.setDeviceState(lbDeviceVO.getState().name());

plugins/network-elements/f5/src/com/cloud/network/resource/F5BigIpResource.java

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ private enum LbProtocol {
119119
private String _privateInterface;
120120
private Integer _numRetries;
121121
private String _guid;
122-
private boolean _inline;
123122

124123
private Interfaces _interfaces;
125124
private LocalLBVirtualServerBindingStub _virtualServerApi;
@@ -180,8 +179,6 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
180179
throw new ConfigurationException("Unable to find the guid");
181180
}
182181

183-
_inline = Boolean.parseBoolean((String) params.get("inline"));
184-
185182
login();
186183

187184
return true;
@@ -292,45 +289,49 @@ private Answer execute(MaintainCommand cmd) {
292289
}
293290

294291
private synchronized Answer execute(IpAssocCommand cmd, int numRetries) {
295-
String[] results = new String[cmd.getIpAddresses().length];
296-
int i = 0;
297-
try {
298-
IpAddressTO[] ips = cmd.getIpAddresses();
299-
for (IpAddressTO ip : ips) {
300-
long guestVlanTag = Long.valueOf(ip.getVlanId());
301-
String vlanSelfIp = _inline ? tagAddressWithRouteDomain(ip.getVlanGateway(), guestVlanTag) : ip.getVlanGateway();
302-
String vlanNetmask = ip.getVlanNetmask();
303-
304-
// Delete any existing guest VLAN with this tag, self IP, and netmask
305-
deleteGuestVlan(guestVlanTag, vlanSelfIp, vlanNetmask);
306-
307-
if (ip.isAdd()) {
308-
// Add a new guest VLAN
309-
addGuestVlan(guestVlanTag, vlanSelfIp, vlanNetmask);
292+
String[] results = new String[cmd.getIpAddresses().length];
293+
int i = 0;
294+
try {
295+
IpAddressTO[] ips = cmd.getIpAddresses();
296+
for (IpAddressTO ip : ips) {
297+
long guestVlanTag = Long.valueOf(ip.getVlanId());
298+
// It's a hack, using isOneToOneNat field for indicate if it's inline or not
299+
// We'd better have an separate SetupGuestNetwork command later
300+
boolean inline = ip.isOneToOneNat();
301+
String vlanSelfIp = inline ? tagAddressWithRouteDomain(ip.getVlanGateway(), guestVlanTag) : ip.getVlanGateway();
302+
String vlanNetmask = ip.getVlanNetmask();
303+
304+
// Delete any existing guest VLAN with this tag, self IP, and netmask
305+
deleteGuestVlan(guestVlanTag, vlanSelfIp, vlanNetmask, inline);
306+
307+
if (ip.isAdd()) {
308+
// Add a new guest VLAN
309+
addGuestVlan(guestVlanTag, vlanSelfIp, vlanNetmask, inline);
310+
}
311+
312+
saveConfiguration();
313+
results[i++] = ip.getPublicIp() + " - success";
310314
}
311-
312-
saveConfiguration();
313-
results[i++] = ip.getPublicIp() + " - success";
314-
}
315-
316-
} catch (ExecutionException e) {
317-
s_logger.error("Failed to execute IPAssocCommand due to " + e);
318-
319-
if (shouldRetry(numRetries)) {
320-
return retry(cmd, numRetries);
321-
} else {
322-
results[i++] = IpAssocAnswer.errorResult;
323-
}
324-
}
325-
326-
return new IpAssocAnswer(cmd, results);
327-
}
315+
316+
} catch (ExecutionException e) {
317+
s_logger.error("Failed to execute IPAssocCommand due to " + e);
318+
319+
if (shouldRetry(numRetries)) {
320+
return retry(cmd, numRetries);
321+
} else {
322+
results[i++] = IpAssocAnswer.errorResult;
323+
}
324+
}
325+
326+
return new IpAssocAnswer(cmd, results);
327+
}
328328

329329
private synchronized Answer execute(LoadBalancerConfigCommand cmd, int numRetries) {
330330
try {
331331
long guestVlanTag = Long.parseLong(cmd.getAccessDetail(NetworkElementCommand.GUEST_VLAN_TAG));
332332
LoadBalancerTO[] loadBalancers = cmd.getLoadBalancers();
333333
for (LoadBalancerTO loadBalancer : loadBalancers) {
334+
boolean inline = loadBalancer.isInline();
334335
LbProtocol lbProtocol;
335336
try {
336337
if (loadBalancer.getProtocol() == null) {
@@ -351,7 +352,7 @@ private synchronized Answer execute(LoadBalancerConfigCommand cmd, int numRetrie
351352
throw new ExecutionException("Got invalid algorithm: " + loadBalancer.getAlgorithm());
352353
}
353354

354-
String srcIp = _inline ? tagAddressWithRouteDomain(loadBalancer.getSrcIp(), guestVlanTag) : loadBalancer.getSrcIp();
355+
String srcIp = inline ? tagAddressWithRouteDomain(loadBalancer.getSrcIp(), guestVlanTag) : loadBalancer.getSrcIp();
355356
int srcPort = loadBalancer.getSrcPort();
356357
String virtualServerName = genVirtualServerName(lbProtocol, srcIp, srcPort);
357358

@@ -371,7 +372,7 @@ private synchronized Answer execute(LoadBalancerConfigCommand cmd, int numRetrie
371372
List<String> activePoolMembers = new ArrayList<String>();
372373
for (DestinationTO destination : loadBalancer.getDestinations()) {
373374
if (!destination.isRevoked()) {
374-
String destIp = _inline ? tagAddressWithRouteDomain(destination.getDestIp(), guestVlanTag) : destination.getDestIp();
375+
String destIp = inline ? tagAddressWithRouteDomain(destination.getDestIp(), guestVlanTag) : destination.getDestIp();
375376
addPoolMember(virtualServerName, destIp, destination.getDestPort());
376377
activePoolMembers.add(destIp + "-" + destination.getDestPort());
377378
}
@@ -421,7 +422,7 @@ private void saveConfiguration() throws ExecutionException {
421422
}
422423
}
423424

424-
private void addGuestVlan(long vlanTag, String vlanSelfIp, String vlanNetmask) throws ExecutionException {
425+
private void addGuestVlan(long vlanTag, String vlanSelfIp, String vlanNetmask, boolean inline) throws ExecutionException {
425426
try {
426427
String vlanName = genVlanName(vlanTag);
427428
List<String> allVlans = getVlans();
@@ -444,7 +445,7 @@ private void addGuestVlan(long vlanTag, String vlanSelfIp, String vlanNetmask) t
444445
}
445446
}
446447

447-
if (_inline) {
448+
if (inline) {
448449
List<Long> allRouteDomains = getRouteDomains();
449450
if (!allRouteDomains.contains(vlanTag)) {
450451
long[] routeDomainIds = genLongArray(vlanTag);
@@ -481,7 +482,7 @@ private void addGuestVlan(long vlanTag, String vlanSelfIp, String vlanNetmask) t
481482

482483
}
483484

484-
private void deleteGuestVlan(long vlanTag, String vlanSelfIp, String vlanNetmask) throws ExecutionException {
485+
private void deleteGuestVlan(long vlanTag, String vlanSelfIp, String vlanNetmask, boolean inline) throws ExecutionException {
485486
try {
486487
// Delete all virtual servers and pools that use this guest VLAN
487488
deleteVirtualServersInGuestVlan(vlanSelfIp, vlanNetmask);
@@ -496,7 +497,7 @@ private void deleteGuestVlan(long vlanTag, String vlanSelfIp, String vlanNetmask
496497
}
497498
}
498499

499-
if (_inline) {
500+
if (inline) {
500501
List<Long> allRouteDomains = getRouteDomains();
501502
if (allRouteDomains.contains(vlanTag)) {
502503
s_logger.debug("Deleting route domain " + vlanTag);
@@ -969,9 +970,7 @@ private ExternalNetworkResourceUsageAnswer getIpBytesSentAndReceived(ExternalNet
969970
for (LocalLBVirtualServerVirtualServerStatisticEntry entry : stats.getStatistics()) {
970971
String virtualServerIp = entry.getVirtual_server().getAddress();
971972

972-
if (_inline) {
973-
virtualServerIp = stripRouteDomainFromAddress(virtualServerIp);
974-
}
973+
virtualServerIp = stripRouteDomainFromAddress(virtualServerIp);
975974

976975
long[] bytesSentAndReceived = answer.ipBytes.get(virtualServerIp);
977976

plugins/network-elements/netscaler/src/com/cloud/api/response/NetscalerLoadBalancerResponse.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ public class NetscalerLoadBalancerResponse extends BaseResponse {
4949
@SerializedName(ApiConstants.LOAD_BALANCER_DEVICE_DEDICATED) @Param(description="true if device is dedicated for an account")
5050
private Boolean dedicatedLoadBalancer;
5151

52-
@SerializedName(ApiConstants.INLINE) @Param(description="true if device is inline with firewall device")
53-
private Boolean inlineLoadBalancer;
54-
5552
@SerializedName(ApiConstants.PUBLIC_INTERFACE) @Param(description="the public interface of the load balancer")
5653
private String publicInterface;
5754

@@ -94,10 +91,6 @@ public void setDeviceState(String deviceState) {
9491
this.deviceState = deviceState;
9592
}
9693

97-
public void setInlineMode(boolean inline) {
98-
this.inlineLoadBalancer = inline;
99-
}
100-
10194
public void setPublicInterface(String publicInterface) {
10295
this.publicInterface = publicInterface;
10396
}

plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -353,18 +353,17 @@ public boolean deleteNetscalerLoadBalancer(DeleteNetscalerLoadBalancerCmd cmd) {
353353
public ExternalLoadBalancerDeviceVO configureNetscalerLoadBalancer(ConfigureNetscalerLoadBalancerCmd cmd) {
354354
Long lbDeviceId = cmd.getLoadBalancerDeviceId();
355355
Boolean dedicatedUse = cmd.getLoadBalancerDedicated();
356-
Boolean inline = cmd.getLoadBalancerInline();
357356
Long capacity = cmd.getLoadBalancerCapacity();
358357
List<Long> podIds = cmd.getPodIds();
359358
try {
360-
return configureNetscalerLoadBalancer(lbDeviceId, capacity, inline, dedicatedUse, podIds);
359+
return configureNetscalerLoadBalancer(lbDeviceId, capacity, dedicatedUse, podIds);
361360
} catch (Exception e) {
362361
throw new CloudRuntimeException("failed to configure netscaler device due to " + e.getMessage());
363362
}
364363
}
365364

366365
@DB
367-
private ExternalLoadBalancerDeviceVO configureNetscalerLoadBalancer(long lbDeviceId, Long capacity, Boolean inline, Boolean dedicatedUse, List<Long> newPodsConfig) {
366+
private ExternalLoadBalancerDeviceVO configureNetscalerLoadBalancer(long lbDeviceId, Long capacity, Boolean dedicatedUse, List<Long> newPodsConfig) {
368367
ExternalLoadBalancerDeviceVO lbDeviceVo = _lbDeviceDao.findById(lbDeviceId);
369368
Map<String, String> lbDetails = _detailsDao.findDetails(lbDeviceVo.getHostId());
370369

@@ -404,7 +403,7 @@ private ExternalLoadBalancerDeviceVO configureNetscalerLoadBalancer(long lbDevic
404403
}
405404

406405
String deviceName = lbDeviceVo.getDeviceName();
407-
if (dedicatedUse != null || capacity != null || inline != null) {
406+
if (dedicatedUse != null || capacity != null) {
408407
if (NetworkDevice.NetscalerSDXLoadBalancer.getName().equalsIgnoreCase(deviceName) ||
409408
NetworkDevice.NetscalerMPXLoadBalancer.getName().equalsIgnoreCase(deviceName)) {
410409
if (dedicatedUse != null && dedicatedUse == true) {
@@ -422,13 +421,6 @@ private ExternalLoadBalancerDeviceVO configureNetscalerLoadBalancer(long lbDevic
422421
if (dedicatedUse != null && dedicatedUse == true) {
423422
throw new CloudRuntimeException("There are networks already using this netscaler device to make device dedicated");
424423
}
425-
426-
if (inline != null) {
427-
boolean _setInline = Boolean.parseBoolean(lbDetails.get("inline"));
428-
if (inline != _setInline) {
429-
throw new CloudRuntimeException("There are networks already using this netscaler device to change the device inline or side-by-side configuration");
430-
}
431-
}
432424
}
433425
}
434426

@@ -444,14 +436,6 @@ private ExternalLoadBalancerDeviceVO configureNetscalerLoadBalancer(long lbDevic
444436
lbDeviceVo.setIsDedicatedDevice(dedicatedUse);
445437
}
446438

447-
if (inline != null && inline == true) {
448-
lbDeviceVo.setIsInlineMode(true);
449-
lbDetails.put("inline", "true");
450-
} else {
451-
lbDeviceVo.setIsInlineMode(false);
452-
lbDetails.put("inline", "false");
453-
}
454-
455439
Transaction txn = Transaction.currentTxn();
456440
txn.start();
457441

@@ -552,7 +536,6 @@ public NetscalerLoadBalancerResponse createNetscalerLoadBalancerResponse(Externa
552536
} else {
553537
response.setDeviceCapacity(lbDeviceVO.getCapacity());
554538
}
555-
response.setInlineMode(lbDeviceVO.getIsInLineMode());
556539
response.setDedicatedLoadBalancer(lbDeviceVO.getIsDedicatedDevice());
557540
response.setProvider(lbDeviceVO.getProviderName());
558541
response.setDeviceState(lbDeviceVO.getState().name());
@@ -690,7 +673,7 @@ public boolean applyElasticLoadBalancerRules(Network network, List<? extends Fir
690673
List<LbDestination> destinations = rule.getDestinations();
691674

692675
if ((destinations != null && !destinations.isEmpty()) || rule.isAutoScaleConfig()) {
693-
LoadBalancerTO loadBalancer = new LoadBalancerTO(lbUuid, srcIp, srcPort, protocol, algorithm, revoked, false, destinations, rule.getStickinessPolicies());
676+
LoadBalancerTO loadBalancer = new LoadBalancerTO(lbUuid, srcIp, srcPort, protocol, algorithm, revoked, false, false, destinations, rule.getStickinessPolicies());
694677
if (rule.isAutoScaleConfig()) {
695678
loadBalancer.setAutoScaleVmGroup(rule.getAutoScaleVmGroup());
696679
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3006,6 +3006,11 @@ public NetworkOfferingResponse createNetworkOfferingResponse(NetworkOffering off
30063006
eLb.setValue(offering.getElasticLb() ? "true" : "false");
30073007
lbCapResponse.add(eLb);
30083008

3009+
CapabilityResponse inline = new CapabilityResponse();
3010+
inline.setName(Capability.InlineMode.getName());
3011+
inline.setValue(offering.isInline() ? "true" : "false");
3012+
lbCapResponse.add(inline);
3013+
30093014
svcRsp.setCapabilities(lbCapResponse);
30103015
} else if (Service.SourceNat == service) {
30113016
List<CapabilityResponse> capabilities = new ArrayList<CapabilityResponse>();

0 commit comments

Comments
 (0)