Skip to content

Commit bb31bc7

Browse files
committed
For VirtualRouter apply networkThrottling rate of the GuestNetworkOffering to both Guest and Public networks.
1 parent 971915a commit bb31bc7

5 files changed

Lines changed: 22 additions & 9 deletions

File tree

‎api/src/com/cloud/configuration/ConfigurationService.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import com.cloud.offering.NetworkOffering;
3535
import com.cloud.offering.ServiceOffering;
3636
import com.cloud.user.Account;
37+
import com.cloud.vm.VirtualMachine;
38+
import com.cloud.vm.VirtualMachine.Type;
3739

3840
public interface ConfigurationService {
3941

@@ -182,7 +184,7 @@ public interface ConfigurationService {
182184

183185
NetworkOffering getNetworkOffering(long id);
184186

185-
Integer getNetworkRate(long networkOfferingId);
187+
Integer getNetworkRate(long networkOfferingId, Type vmType);
186188

187189
Account getVlanAccount(long vlanId);
188190

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ public static Long getVlanNetworkId(long vlanId) {
524524
}
525525

526526
public static Integer getNetworkRate(long networkOfferingId) {
527-
return _configMgr.getNetworkRate(networkOfferingId);
527+
return _configMgr.getNetworkRate(networkOfferingId, null);
528528
}
529529

530530
public static Account getVlanAccount(long vlanId) {

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@
127127
import com.cloud.utils.exception.CloudRuntimeException;
128128
import com.cloud.utils.net.NetUtils;
129129
import com.cloud.vm.VMInstanceVO;
130+
import com.cloud.vm.VirtualMachine;
131+
import com.cloud.vm.VirtualMachine.Type;
130132
import com.cloud.vm.dao.ConsoleProxyDao;
131133
import com.cloud.vm.dao.DomainRouterDao;
132134
import com.cloud.vm.dao.SecondaryStorageVmDao;
@@ -2779,14 +2781,23 @@ public NetworkOffering getNetworkOffering(long id) {
27792781
}
27802782

27812783
@Override
2782-
public Integer getNetworkRate(long networkOfferingId) {
2784+
public Integer getNetworkRate(long networkOfferingId, Type vmType) {
27832785

27842786
//validate network offering information
27852787
NetworkOffering no = getNetworkOffering(networkOfferingId);
27862788
if (no == null) {
27872789
throw new InvalidParameterValueException("Unable to find network offering by id=" + networkOfferingId);
27882790
}
27892791

2792+
//For router's public network we use networkRate from guestNetworkOffering
2793+
if (vmType != null && vmType == VirtualMachine.Type.DomainRouter && no.getTrafficType() == TrafficType.Public && no.getGuestType() == null) {
2794+
List<? extends NetworkOffering> guestOfferings = _networkOfferingDao.listByTrafficTypeAndGuestType(false, TrafficType.Guest, GuestIpType.Virtual);
2795+
if (!guestOfferings.isEmpty()) {
2796+
//We have one default guest virtual network offering now
2797+
no = guestOfferings.get(0);
2798+
}
2799+
}
2800+
27902801
Integer networkRate;
27912802
if (no.getRateMbps() != null) {
27922803
networkRate = no.getRateMbps();

‎server/src/com/cloud/network/NetworkManagerImpl.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ public void allocate(VirtualMachineProfile<? extends VMInstanceVO> vm, List<Pair
982982
nics.add(vo);
983983

984984
NetworkOffering no = _configMgr.getNetworkOffering(config.getNetworkOfferingId());
985-
Integer networkRate = _configMgr.getNetworkRate(no.getId());
985+
Integer networkRate = _configMgr.getNetworkRate(no.getId(), vm.getType());
986986
vm.addNic(new NicProfile(vo, network.first(), vo.getBroadcastUri(), vo.getIsolationUri(), networkRate));
987987
}
988988

@@ -1075,7 +1075,7 @@ protected NicTO toNicTO(NicVO nic, NicProfile profile, NetworkVO config) {
10751075
to.setDns2(profile.getDns2());
10761076
}
10771077

1078-
Integer networkRate = _configMgr.getNetworkRate(config.getNetworkOfferingId());
1078+
Integer networkRate = _configMgr.getNetworkRate(config.getNetworkOfferingId(), null);
10791079
to.setNetworkRateMbps(networkRate);
10801080

10811081
return to;
@@ -1196,7 +1196,7 @@ public int compare(NicVO nic1, NicVO nic2){
11961196
NetworkGuru guru = implemented.first();
11971197
NetworkVO network = implemented.second();
11981198
NetworkOffering no = _configMgr.getNetworkOffering(network.getNetworkOfferingId());
1199-
Integer networkRate = _configMgr.getNetworkRate(no.getId());
1199+
Integer networkRate = _configMgr.getNetworkRate(no.getId(), vmProfile.getType());
12001200
NicProfile profile = null;
12011201
if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) {
12021202
nic.setState(Nic.State.Reserving);
@@ -1246,7 +1246,7 @@ public <T extends VMInstanceVO> void prepareNicForMigration(VirtualMachineProfil
12461246
for (NicVO nic : nics) {
12471247
NetworkVO network = _networksDao.findById(nic.getNetworkId());
12481248
NetworkOffering no = _configMgr.getNetworkOffering(network.getNetworkOfferingId());
1249-
Integer networkRate = _configMgr.getNetworkRate(no.getId());
1249+
Integer networkRate = _configMgr.getNetworkRate(no.getId(), vm.getType());
12501250

12511251
NetworkGuru guru = _networkGurus.get(network.getGuruName());
12521252
NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate);
@@ -1303,7 +1303,7 @@ public List<NicProfile> getNicProfiles(VirtualMachine vm) {
13031303
for (Nic nic : nics) {
13041304
NetworkVO network = _networksDao.findById(nic.getNetworkId());
13051305
NetworkOffering no = _configMgr.getNetworkOffering(network.getNetworkOfferingId());
1306-
Integer networkRate = _configMgr.getNetworkRate(no.getId());
1306+
Integer networkRate = _configMgr.getNetworkRate(no.getId(), vm.getType());
13071307

13081308
NetworkGuru guru = _networkGurus.get(network.getGuruName());
13091309
NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate);

‎server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,7 @@ public int compare(PublicIpAddress o1, PublicIpAddress o2) {
14171417
//Get network rate - required for IpAssoc
14181418
Network network = _networkMgr.getNetwork(ipAddr.getNetworkId());
14191419
NetworkOffering no = _configMgr.getNetworkOffering(network.getNetworkOfferingId());
1420-
Integer networkRate = _configMgr.getNetworkRate(no.getId());
1420+
Integer networkRate = _configMgr.getNetworkRate(no.getId(), null);
14211421

14221422
IpAddressTO ip = new IpAddressTO(ipAddr.getAddress().addr(), add, firstIP, sourceNat, vlanId, vlanGateway, vlanNetmask, vifMacAddress, vmGuestAddress, networkRate);
14231423
ipsToSend[i++] = ip;

0 commit comments

Comments
 (0)