Skip to content

Commit 5d72b63

Browse files
KDDI-105: Network rate use network's offering for VR public/guest nics
This makes VR's guest/public nics to pick network rate from the network offering of the VR (if defined), otherwise pick the value from global setting `network.throttling.rate`. This conforms with the definition here: http://docs.cloudstack.apache.org/projects/cloudstack-administration/en/4.9/service_offerings.html#network-throttling Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent ebf9b49 commit 5d72b63

File tree

2 files changed

+39
-28
lines changed

2 files changed

+39
-28
lines changed

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ private UnPlugNicAnswer execute(UnPlugNicCommand cmd) {
11141114
}
11151115
}
11161116

1117-
private void plugPublicNic(VirtualMachineMO vmMo, final String vlanId, final String vifMacAddress) throws Exception {
1117+
private void plugPublicNic(VirtualMachineMO vmMo, final String vlanId, final IpAddressTO ipAddressTO) throws Exception {
11181118
// TODO : probably need to set traffic shaping
11191119
Pair<ManagedObjectReference, String> networkInfo = null;
11201120
VirtualSwitchType vSwitchType = VirtualSwitchType.StandardVirtualSwitch;
@@ -1126,11 +1126,11 @@ private void plugPublicNic(VirtualMachineMO vmMo, final String vlanId, final Str
11261126
*/
11271127
if (VirtualSwitchType.StandardVirtualSwitch == vSwitchType) {
11281128
networkInfo = HypervisorHostHelper.prepareNetwork(_publicTrafficInfo.getVirtualSwitchName(),
1129-
"cloud.public", vmMo.getRunningHost(), vlanId, null, null,
1129+
"cloud.public", vmMo.getRunningHost(), vlanId, ipAddressTO.getNetworkRate(), null,
11301130
_opsTimeout, true, BroadcastDomainType.Vlan, null);
11311131
} else {
11321132
networkInfo =
1133-
HypervisorHostHelper.prepareNetwork(_publicTrafficInfo.getVirtualSwitchName(), "cloud.public", vmMo.getRunningHost(), vlanId, null, null, null,
1133+
HypervisorHostHelper.prepareNetwork(_publicTrafficInfo.getVirtualSwitchName(), "cloud.public", vmMo.getRunningHost(), vlanId, null, ipAddressTO.getNetworkRate(), null,
11341134
_opsTimeout, vSwitchType, _portsPerDvPortGroup, null, false, BroadcastDomainType.Vlan, _vsmCredentials);
11351135
}
11361136

@@ -1246,7 +1246,7 @@ private ExecutionResult prepareNetworkElementCommand(IpAssocCommand cmd) {
12461246
}
12471247

12481248
if (addVif) {
1249-
plugPublicNic(vmMo, vlanId, ip.getVifMacAddress());
1249+
plugPublicNic(vmMo, vlanId, ip);
12501250
publicNicInfo = vmMo.getNicDeviceIndex(publicNeworkName);
12511251
if (publicNicInfo.first().intValue() >= 0) {
12521252
networkUsage(controlIp, "addVif", "eth" + publicNicInfo.first());

server/src/com/cloud/network/NetworkModelImpl.java

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import javax.naming.ConfigurationException;
3535

3636
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
37+
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
3738
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
3839
import org.apache.cloudstack.lb.dao.ApplicationLoadBalancerRuleDao;
3940
import org.apache.commons.codec.binary.Base64;
@@ -990,33 +991,43 @@ public Integer getNetworkRate(long networkId, Long vmId) {
990991
if (vmId != null) {
991992
vm = _vmDao.findById(vmId);
992993
}
993-
Network network = getNetwork(networkId);
994-
NetworkOffering ntwkOff = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
995-
996-
// For default userVm Default network and domR guest/public network, get rate information from the service
997-
// offering; for other situations get information
998-
// from the network offering
999-
boolean isUserVmsDefaultNetwork = false;
1000-
boolean isDomRGuestOrPublicNetwork = false;
1001-
boolean isSystemVmNetwork = false;
994+
final Network network = getNetwork(networkId);
995+
final NetworkOffering ntwkOff = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
996+
997+
// For user VM: For default nic use network rate from the service/compute offering,
998+
// or on NULL from vm.network.throttling.rate global setting
999+
// For router: Get network rate for guest and public networks from the guest network offering
1000+
// or on NULL from network.throttling.rate
1001+
// For others: Use network rate from their network offering,
1002+
// or on NULL from network.throttling.rate setting at zone > global level
1003+
// http://docs.cloudstack.apache.org/projects/cloudstack-administration/en/latest/service_offerings.html#network-throttling
10021004
if (vm != null) {
1003-
Nic nic = _nicDao.findByNtwkIdAndInstanceId(networkId, vmId);
1004-
if (vm.getType() == Type.User && nic != null && nic.isDefaultNic()) {
1005-
isUserVmsDefaultNetwork = true;
1006-
} else if (vm.getType() == Type.DomainRouter && ntwkOff != null &&
1007-
(ntwkOff.getTrafficType() == TrafficType.Public || ntwkOff.getTrafficType() == TrafficType.Guest)) {
1008-
isDomRGuestOrPublicNetwork = true;
1009-
} else if (vm.getType() == Type.ConsoleProxy || vm.getType() == Type.SecondaryStorageVm) {
1010-
isSystemVmNetwork = true;
1011-
}
1012-
}
1013-
if (isUserVmsDefaultNetwork || isDomRGuestOrPublicNetwork) {
1014-
return _configMgr.getServiceOfferingNetworkRate(vm.getServiceOfferingId(), network.getDataCenterId());
1015-
} else if (isSystemVmNetwork) {
1016-
return -1;
1017-
} else {
1005+
if (vm.getType() == Type.User) {
1006+
final Nic nic = _nicDao.findByNtwkIdAndInstanceId(networkId, vmId);
1007+
if (nic != null && nic.isDefaultNic()) {
1008+
return _configMgr.getServiceOfferingNetworkRate(vm.getServiceOfferingId(), network.getDataCenterId());
1009+
}
1010+
}
1011+
if (vm.getType() == Type.DomainRouter && (network.getTrafficType() == TrafficType.Public || network.getTrafficType() == TrafficType.Guest)) {
1012+
for (final Nic nic: _nicDao.listByVmId(vmId)) {
1013+
final NetworkVO nw = _networksDao.findById(nic.getNetworkId());
1014+
if (nw.getTrafficType() == TrafficType.Guest) {
1015+
return _configMgr.getNetworkOfferingNetworkRate(nw.getNetworkOfferingId(), network.getDataCenterId());
1016+
}
1017+
}
1018+
}
1019+
if (vm.getType() == Type.ConsoleProxy || vm.getType() == Type.SecondaryStorageVm) {
1020+
return -1;
1021+
}
1022+
}
1023+
if (ntwkOff != null) {
10181024
return _configMgr.getNetworkOfferingNetworkRate(ntwkOff.getId(), network.getDataCenterId());
10191025
}
1026+
final Integer networkRate = NetworkOrchestrationService.NetworkThrottlingRate.valueIn(network.getDataCenterId());
1027+
if (networkRate != null && networkRate > 0) {
1028+
return networkRate;
1029+
}
1030+
return -1;
10201031
}
10211032

10221033
@Override

0 commit comments

Comments
 (0)