Skip to content

Commit 03e65a1

Browse files
ustcweizhouDaanHoogland
authored andcommitted
vpc vr: plugin nics by this order: public/private/guest
1 parent 627070c commit 03e65a1

5 files changed

Lines changed: 75 additions & 65 deletions

File tree

server/src/main/java/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,19 @@ public boolean finalizeCommandsOnStart(final Commands cmds, final VirtualMachine
314314
// 2) FORM PLUG NIC COMMANDS
315315
final List<Pair<Nic, Network>> guestNics = new ArrayList<Pair<Nic, Network>>();
316316
final List<Pair<Nic, Network>> publicNics = new ArrayList<Pair<Nic, Network>>();
317+
final List<Pair<Nic, Network>> privateGatewayNics = new ArrayList<Pair<Nic, Network>>();
317318
final Map<String, String> vlanMacAddress = new HashMap<String, String>();
318319

319320
final List<? extends Nic> routerNics = _nicDao.listByVmIdOrderByDeviceId(profile.getId());
320321
for (final Nic routerNic : routerNics) {
321322
final Network network = _networkModel.getNetwork(routerNic.getNetworkId());
322323
if (network.getTrafficType() == TrafficType.Guest) {
323324
final Pair<Nic, Network> guestNic = new Pair<Nic, Network>(routerNic, network);
324-
guestNics.add(guestNic);
325+
if (_networkModel.isPrivateGateway(routerNic.getNetworkId())) {
326+
privateGatewayNics.add(guestNic);
327+
} else {
328+
guestNics.add(guestNic);
329+
}
325330
} else if (network.getTrafficType() == TrafficType.Public) {
326331
final Pair<Nic, Network> publicNic = new Pair<Nic, Network>(routerNic, network);
327332
publicNics.add(publicNic);
@@ -375,43 +380,48 @@ public boolean finalizeCommandsOnStart(final Commands cmds, final VirtualMachine
375380
_commandSetupHelper.createVpcAssociatePublicIPCommands(domainRouterVO, sourceNat, cmds, vlanMacAddress);
376381
}
377382

383+
// add VPC router to private gateway networks
384+
for (final Pair<Nic, Network> nicNtwk : privateGatewayNics) {
385+
final Nic guestNic = updateNicWithDeviceId(nicNtwk.first().getId(), deviceId);
386+
deviceId ++;
387+
// plug guest nic
388+
final PlugNicCommand plugNicCmd = new PlugNicCommand(_nwHelper.getNicTO(domainRouterVO, guestNic.getNetworkId(), null), domainRouterVO.getInstanceName(), domainRouterVO.getType(), details);
389+
cmds.addCommand(plugNicCmd);
390+
// set private network
391+
final PrivateIpVO ipVO = _privateIpDao.findByIpAndSourceNetworkId(guestNic.getNetworkId(), guestNic.getIPv4Address());
392+
final Network network = _networkDao.findById(guestNic.getNetworkId());
393+
BroadcastDomainType.getValue(network.getBroadcastUri());
394+
final String netmask = NetUtils.getCidrNetmask(network.getCidr());
395+
final PrivateIpAddress ip = new PrivateIpAddress(ipVO, network.getBroadcastUri().toString(), network.getGateway(), netmask, guestNic.getMacAddress());
396+
397+
final List<PrivateIpAddress> privateIps = new ArrayList<PrivateIpAddress>(1);
398+
privateIps.add(ip);
399+
_commandSetupHelper.createVpcAssociatePrivateIPCommands(domainRouterVO, privateIps, cmds, true);
400+
401+
final Long privateGwAclId = _vpcGatewayDao.getNetworkAclIdForPrivateIp(ipVO.getVpcId(), ipVO.getNetworkId(), ipVO.getIpAddress());
402+
403+
if (privateGwAclId != null) {
404+
// set network acl on private gateway
405+
final List<NetworkACLItemVO> networkACLs = _networkACLItemDao.listByACL(privateGwAclId);
406+
s_logger.debug("Found " + networkACLs.size() + " network ACLs to apply as a part of VPC VR " + domainRouterVO + " start for private gateway ip = "
407+
+ ipVO.getIpAddress());
408+
409+
_commandSetupHelper.createNetworkACLsCommands(networkACLs, domainRouterVO, cmds, ipVO.getNetworkId(), true);
410+
}
411+
}
412+
378413
// add VPC router to guest networks
379414
for (final Pair<Nic, Network> nicNtwk : guestNics) {
380415
final Nic guestNic = updateNicWithDeviceId(nicNtwk.first().getId(), deviceId);
381416
deviceId ++;
382417
// plug guest nic
383418
final PlugNicCommand plugNicCmd = new PlugNicCommand(_nwHelper.getNicTO(domainRouterVO, guestNic.getNetworkId(), null), domainRouterVO.getInstanceName(), domainRouterVO.getType(), details);
384419
cmds.addCommand(plugNicCmd);
385-
if (!_networkModel.isPrivateGateway(guestNic.getNetworkId())) {
386-
// set guest network
387-
final VirtualMachine vm = _vmDao.findById(domainRouterVO.getId());
388-
final NicProfile nicProfile = _networkModel.getNicProfile(vm, guestNic.getNetworkId(), null);
389-
final SetupGuestNetworkCommand setupCmd = _commandSetupHelper.createSetupGuestNetworkCommand(domainRouterVO, true, nicProfile);
390-
cmds.addCommand(setupCmd);
391-
} else {
392-
393-
// set private network
394-
final PrivateIpVO ipVO = _privateIpDao.findByIpAndSourceNetworkId(guestNic.getNetworkId(), guestNic.getIPv4Address());
395-
final Network network = _networkDao.findById(guestNic.getNetworkId());
396-
BroadcastDomainType.getValue(network.getBroadcastUri());
397-
final String netmask = NetUtils.getCidrNetmask(network.getCidr());
398-
final PrivateIpAddress ip = new PrivateIpAddress(ipVO, network.getBroadcastUri().toString(), network.getGateway(), netmask, guestNic.getMacAddress());
399-
400-
final List<PrivateIpAddress> privateIps = new ArrayList<PrivateIpAddress>(1);
401-
privateIps.add(ip);
402-
_commandSetupHelper.createVpcAssociatePrivateIPCommands(domainRouterVO, privateIps, cmds, true);
403-
404-
final Long privateGwAclId = _vpcGatewayDao.getNetworkAclIdForPrivateIp(ipVO.getVpcId(), ipVO.getNetworkId(), ipVO.getIpAddress());
405-
406-
if (privateGwAclId != null) {
407-
// set network acl on private gateway
408-
final List<NetworkACLItemVO> networkACLs = _networkACLItemDao.listByACL(privateGwAclId);
409-
s_logger.debug("Found " + networkACLs.size() + " network ACLs to apply as a part of VPC VR " + domainRouterVO + " start for private gateway ip = "
410-
+ ipVO.getIpAddress());
411-
412-
_commandSetupHelper.createNetworkACLsCommands(networkACLs, domainRouterVO, cmds, ipVO.getNetworkId(), true);
413-
}
414-
}
420+
// set guest network
421+
final VirtualMachine vm = _vmDao.findById(domainRouterVO.getId());
422+
final NicProfile nicProfile = _networkModel.getNicProfile(vm, guestNic.getNetworkId(), null);
423+
final SetupGuestNetworkCommand setupCmd = _commandSetupHelper.createSetupGuestNetworkCommand(domainRouterVO, true, nicProfile);
424+
cmds.addCommand(setupCmd);
415425
}
416426
} catch (final Exception ex) {
417427
s_logger.warn("Failed to add router " + domainRouterVO + " to network due to exception ", ex);

test/integration/component/test_multiple_subnets_in_isolated_network.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ def test_01_acquire_public_ips_in_isolated_network_with_single_vr(self):
429429
# 6. create new public ip range 1
430430
self.services["publiciprange"]["zoneid"] = self.zone.id
431431
self.services["publiciprange"]["forvirtualnetwork"] = "true"
432-
random_subnet_number = random.randrange(10,20)
432+
random_subnet_number = random.randrange(10,50)
433433
self.services["publiciprange"]["vlan"] = get_free_vlan(
434434
self.apiclient,
435435
self.zone.id)[1]

test/integration/component/test_multiple_subnets_in_isolated_network_rvr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ def test_02_acquire_public_ips_in_isolated_network_with_redundant_vrs(self):
429429
# 6. create new public ip range 1
430430
self.services["publiciprange"]["zoneid"] = self.zone.id
431431
self.services["publiciprange"]["forvirtualnetwork"] = "true"
432-
random_subnet_number = random.randrange(10,20)
432+
random_subnet_number = random.randrange(10,50)
433433
self.services["publiciprange"]["vlan"] = get_free_vlan(
434434
self.apiclient,
435435
self.zone.id)[1]

test/integration/component/test_multiple_subnets_in_vpc.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,13 @@ def test_03_acquire_public_ips_in_vpc_with_single_vr(self):
328328
# verify the IPs in VR. eth1 -> source nat IP, eth2 -> tier 1, eth4 -> tier 2, eth5 -> new ip 6, eth3-> private gateway
329329
# 24. reboot router
330330
# verify the available nics in VR should be "eth0,eth1,eth2,eth3,eth4,eth5,"
331-
# verify the IPs in VR. eth1 -> source nat IP, eth2 -> new ip 6, eth3 -> tier 1, eth4 -> private gateway, eth5 -> tier 2
331+
# verify the IPs in VR. eth1 -> source nat IP, eth2 -> new ip 6, eth3 -> private gateway, eth4 -> tier 1, eth5 -> tier 2
332332
# 25. restart VPC with cleanup
333333
# verify the available nics in VR should be "eth0,eth1,eth2,eth3,eth4,eth5,"
334-
# verify the IPs in VR. eth1 -> source nat IP, eth2 -> new ip 6, eth3 -> tier 1, eth4 -> private gateway, eth5 -> tier 2
334+
# verify the IPs in VR. eth1 -> source nat IP, eth2 -> new ip 6, eth3 -> private gateway, eth4 -> tier 1, eth5 -> tier 2
335335
# 26. restart VPC with cleanup, makeredundant=true
336336
# verify the available nics in VR should be "eth0,eth1,eth2,eth3,eth4,eth5,"
337-
# verify the IPs in VR. eth1 -> source nat IP, eth2 -> new ip 6, eth3 -> tier 1, eth4 -> private gateway, eth5 -> tier 2
337+
# verify the IPs in VR. eth1 -> source nat IP, eth2 -> new ip 6, eth3 -> private gateway, eth4 -> tier 1, eth5 -> tier 2
338338
"""
339339

340340
# Create new domain1
@@ -479,7 +479,7 @@ def test_03_acquire_public_ips_in_vpc_with_single_vr(self):
479479
# 6. create new public ip range 1
480480
self.services["publiciprange"]["zoneid"] = self.zone.id
481481
self.services["publiciprange"]["forvirtualnetwork"] = "true"
482-
random_subnet_number = random.randrange(10,20)
482+
random_subnet_number = random.randrange(10,50)
483483
self.services["publiciprange"]["vlan"] = get_free_vlan(
484484
self.apiclient,
485485
self.zone.id)[1]
@@ -900,7 +900,7 @@ def test_03_acquire_public_ips_in_vpc_with_single_vr(self):
900900

901901
# 24. reboot router
902902
# verify the available nics in VR should be "eth0,eth1,eth2,eth3,eth4,eth5,"
903-
# verify the IPs in VR. eth1 -> source nat IP, eth2 -> new ip 6, eth3 -> tier 1, eth4 -> private gateway, eth5 -> tier 2
903+
# verify the IPs in VR. eth1 -> source nat IP, eth2 -> new ip 6, eth3 -> private gateway, eth4 -> tier 1, eth5 -> tier 2
904904
routers = self.get_vpc_routers(self.vpc1.id)
905905
if len(routers) > 0:
906906
router = routers[0]
@@ -914,14 +914,14 @@ def test_03_acquire_public_ips_in_vpc_with_single_vr(self):
914914
self.verify_ip_address_in_router(router, host, controlIp, "eth0", True)
915915
self.verify_ip_address_in_router(router, host, sourcenatIp, "eth1", True)
916916
self.verify_ip_address_in_router(router, host, ipaddress_6.ipaddress.ipaddress, "eth2", True)
917-
self.verify_ip_address_in_router(router, host, tier1_Ip, "eth3", True)
918-
self.verify_ip_address_in_router(router, host, private_gateway_ip, "eth4", True)
917+
self.verify_ip_address_in_router(router, host, private_gateway_ip, "eth3", True)
918+
self.verify_ip_address_in_router(router, host, tier1_Ip, "eth4", True)
919919
self.verify_ip_address_in_router(router, host, tier2_Ip, "eth5", True)
920-
self.verify_router_publicnic_state(router, host, "eth1|eth2|eth4")
920+
self.verify_router_publicnic_state(router, host, "eth1|eth2|eth3")
921921

922922
# 25. restart VPC with cleanup
923923
# verify the available nics in VR should be "eth0,eth1,eth2,eth3,eth4,eth5,"
924-
# verify the IPs in VR. eth1 -> source nat IP, eth2 -> new ip 6, eth3 -> tier 1, eth4 -> private gateway, eth5 -> tier 2
924+
# verify the IPs in VR. eth1 -> source nat IP, eth2 -> new ip 6, eth3 -> private gateway, eth4 -> tier 1, eth5 -> tier 2
925925
self.vpc1.restart(self.apiclient, cleanup=True)
926926
routers = self.get_vpc_routers(self.vpc1.id)
927927
for router in routers:
@@ -931,14 +931,14 @@ def test_03_acquire_public_ips_in_vpc_with_single_vr(self):
931931
self.verify_ip_address_in_router(router, host, controlIp, "eth0", True)
932932
self.verify_ip_address_in_router(router, host, sourcenatIp, "eth1", True)
933933
self.verify_ip_address_in_router(router, host, ipaddress_6.ipaddress.ipaddress, "eth2", True)
934-
self.verify_ip_address_in_router(router, host, tier1_Ip, "eth3", True)
935-
self.verify_ip_address_in_router(router, host, private_gateway_ip, "eth4", True)
934+
self.verify_ip_address_in_router(router, host, private_gateway_ip, "eth3", True)
935+
self.verify_ip_address_in_router(router, host, tier1_Ip, "eth4", True)
936936
self.verify_ip_address_in_router(router, host, tier2_Ip, "eth5", True)
937-
self.verify_router_publicnic_state(router, host, "eth1|eth2|eth4")
937+
self.verify_router_publicnic_state(router, host, "eth1|eth2|eth3")
938938

939939
# 26. restart VPC with cleanup, makeredundant=true
940940
# verify the available nics in VR should be "eth0,eth1,eth2,eth3,eth4,eth5,"
941-
# verify the IPs in VR. eth1 -> source nat IP, eth2 -> new ip 6, eth3 -> tier 1, eth4 -> private gateway, eth5 -> tier 2
941+
# verify the IPs in VR. eth1 -> source nat IP, eth2 -> new ip 6, eth3 -> private gateway, eth4 -> tier 1, eth5 -> tier 2
942942
self.vpc1.restart(self.apiclient, cleanup=True, makeredundant=True)
943943
routers = self.get_vpc_routers(self.vpc1.id)
944944
for router in routers:
@@ -948,7 +948,7 @@ def test_03_acquire_public_ips_in_vpc_with_single_vr(self):
948948
self.verify_ip_address_in_router(router, host, controlIp, "eth0", True)
949949
self.verify_ip_address_in_router(router, host, sourcenatIp, "eth1", True)
950950
self.verify_ip_address_in_router(router, host, ipaddress_6.ipaddress.ipaddress, "eth2", True)
951-
self.verify_ip_address_in_router(router, host, tier1_Ip, "eth3", True)
952-
self.verify_ip_address_in_router(router, host, private_gateway_ip, "eth4", True)
951+
self.verify_ip_address_in_router(router, host, private_gateway_ip, "eth3", True)
952+
self.verify_ip_address_in_router(router, host, tier1_Ip, "eth4", True)
953953
self.verify_ip_address_in_router(router, host, tier2_Ip, "eth5", True)
954-
self.verify_router_publicnic_state(router, host, "eth1|eth2|eth4")
954+
self.verify_router_publicnic_state(router, host, "eth1|eth2|eth3")

0 commit comments

Comments
 (0)