From bb31bc779fa020ecbba4c62177b2e918ed19975b Mon Sep 17 00:00:00 2001 From: alena Date: Wed, 30 Mar 2011 14:48:21 -0700 Subject: [PATCH] For VirtualRouter apply networkThrottling rate of the GuestNetworkOffering to both Guest and Public networks. --- .../cloud/configuration/ConfigurationService.java | 4 +++- server/src/com/cloud/api/ApiDBUtils.java | 2 +- .../configuration/ConfigurationManagerImpl.java | 13 ++++++++++++- .../src/com/cloud/network/NetworkManagerImpl.java | 10 +++++----- .../router/VirtualNetworkApplianceManagerImpl.java | 2 +- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/api/src/com/cloud/configuration/ConfigurationService.java b/api/src/com/cloud/configuration/ConfigurationService.java index f5b3c71aea5..426b759d56d 100644 --- a/api/src/com/cloud/configuration/ConfigurationService.java +++ b/api/src/com/cloud/configuration/ConfigurationService.java @@ -34,6 +34,8 @@ import com.cloud.offering.DiskOffering; import com.cloud.offering.NetworkOffering; import com.cloud.offering.ServiceOffering; import com.cloud.user.Account; +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachine.Type; public interface ConfigurationService { @@ -182,7 +184,7 @@ public interface ConfigurationService { NetworkOffering getNetworkOffering(long id); - Integer getNetworkRate(long networkOfferingId); + Integer getNetworkRate(long networkOfferingId, Type vmType); Account getVlanAccount(long vlanId); diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java index 1d99e5ede0b..987b13a84ae 100755 --- a/server/src/com/cloud/api/ApiDBUtils.java +++ b/server/src/com/cloud/api/ApiDBUtils.java @@ -524,7 +524,7 @@ public class ApiDBUtils { } public static Integer getNetworkRate(long networkOfferingId) { - return _configMgr.getNetworkRate(networkOfferingId); + return _configMgr.getNetworkRate(networkOfferingId, null); } public static Account getVlanAccount(long vlanId) { diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 8ded152d2a0..6529ea963b7 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -127,6 +127,8 @@ import com.cloud.utils.db.Transaction; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.NetUtils; import com.cloud.vm.VMInstanceVO; +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachine.Type; import com.cloud.vm.dao.ConsoleProxyDao; import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.SecondaryStorageVmDao; @@ -2779,7 +2781,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } @Override - public Integer getNetworkRate(long networkOfferingId) { + public Integer getNetworkRate(long networkOfferingId, Type vmType) { //validate network offering information NetworkOffering no = getNetworkOffering(networkOfferingId); @@ -2787,6 +2789,15 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura throw new InvalidParameterValueException("Unable to find network offering by id=" + networkOfferingId); } + //For router's public network we use networkRate from guestNetworkOffering + if (vmType != null && vmType == VirtualMachine.Type.DomainRouter && no.getTrafficType() == TrafficType.Public && no.getGuestType() == null) { + List guestOfferings = _networkOfferingDao.listByTrafficTypeAndGuestType(false, TrafficType.Guest, GuestIpType.Virtual); + if (!guestOfferings.isEmpty()) { + //We have one default guest virtual network offering now + no = guestOfferings.get(0); + } + } + Integer networkRate; if (no.getRateMbps() != null) { networkRate = no.getRateMbps(); diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 7ac676bc754..b3dfd7e56bd 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -982,7 +982,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag nics.add(vo); NetworkOffering no = _configMgr.getNetworkOffering(config.getNetworkOfferingId()); - Integer networkRate = _configMgr.getNetworkRate(no.getId()); + Integer networkRate = _configMgr.getNetworkRate(no.getId(), vm.getType()); vm.addNic(new NicProfile(vo, network.first(), vo.getBroadcastUri(), vo.getIsolationUri(), networkRate)); } @@ -1075,7 +1075,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag to.setDns2(profile.getDns2()); } - Integer networkRate = _configMgr.getNetworkRate(config.getNetworkOfferingId()); + Integer networkRate = _configMgr.getNetworkRate(config.getNetworkOfferingId(), null); to.setNetworkRateMbps(networkRate); return to; @@ -1196,7 +1196,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag NetworkGuru guru = implemented.first(); NetworkVO network = implemented.second(); NetworkOffering no = _configMgr.getNetworkOffering(network.getNetworkOfferingId()); - Integer networkRate = _configMgr.getNetworkRate(no.getId()); + Integer networkRate = _configMgr.getNetworkRate(no.getId(), vmProfile.getType()); NicProfile profile = null; if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) { nic.setState(Nic.State.Reserving); @@ -1246,7 +1246,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag for (NicVO nic : nics) { NetworkVO network = _networksDao.findById(nic.getNetworkId()); NetworkOffering no = _configMgr.getNetworkOffering(network.getNetworkOfferingId()); - Integer networkRate = _configMgr.getNetworkRate(no.getId()); + Integer networkRate = _configMgr.getNetworkRate(no.getId(), vm.getType()); NetworkGuru guru = _networkGurus.get(network.getGuruName()); NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate); @@ -1303,7 +1303,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag for (Nic nic : nics) { NetworkVO network = _networksDao.findById(nic.getNetworkId()); NetworkOffering no = _configMgr.getNetworkOffering(network.getNetworkOfferingId()); - Integer networkRate = _configMgr.getNetworkRate(no.getId()); + Integer networkRate = _configMgr.getNetworkRate(no.getId(), vm.getType()); NetworkGuru guru = _networkGurus.get(network.getGuruName()); NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate); diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 93e38226b1f..3b854fc36f9 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -1417,7 +1417,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian //Get network rate - required for IpAssoc Network network = _networkMgr.getNetwork(ipAddr.getNetworkId()); NetworkOffering no = _configMgr.getNetworkOffering(network.getNetworkOfferingId()); - Integer networkRate = _configMgr.getNetworkRate(no.getId()); + Integer networkRate = _configMgr.getNetworkRate(no.getId(), null); IpAddressTO ip = new IpAddressTO(ipAddr.getAddress().addr(), add, firstIP, sourceNat, vlanId, vlanGateway, vlanNetmask, vifMacAddress, vmGuestAddress, networkRate); ipsToSend[i++] = ip;