Skip to content

Commit 4a14ea8

Browse files
author
Sheng Yang
committed
CLOUDSTACK-1771: Fix ipv6 address for router
Now it won't change(as ipv4 address) after router is destroyed.
1 parent 5541785 commit 4a14ea8

10 files changed

Lines changed: 48 additions & 44 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ public boolean manageGuestNetworkWithExternalFirewall(boolean add, Network netwo
485485

486486
if (add && (!reservedIpAddressesForGuestNetwork.contains(network.getGateway()))) {
487487
// Insert a new NIC for this guest network to reserve the gateway address
488-
_networkMgr.savePlaceholderNic(network, network.getGateway(), null);
488+
_networkMgr.savePlaceholderNic(network, network.getGateway(), null, null);
489489
}
490490

491491
// Delete any mappings used for inline external load balancers in this network

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ private MappingNic getLoadBalancingIpNic(DataCenterVO zone, Network network, lon
774774
// If a NIC doesn't exist for the load balancing IP address, create one
775775
loadBalancingIpNic = _nicDao.findByIp4AddressAndNetworkId(loadBalancingIpAddress, network.getId());
776776
if (loadBalancingIpNic == null) {
777-
loadBalancingIpNic = _networkMgr.savePlaceholderNic(network, loadBalancingIpAddress, null);
777+
loadBalancingIpNic = _networkMgr.savePlaceholderNic(network, loadBalancingIpAddress, null, null);
778778
}
779779

780780
// Save a mapping between the source IP address and the load balancing IP address NIC
@@ -1019,7 +1019,7 @@ public boolean manageGuestNetworkWithExternalLoadBalancer(boolean add, Network g
10191019

10201020
if (add) {
10211021
// Insert a new NIC for this guest network to reserve the self IP
1022-
_networkMgr.savePlaceholderNic(guestConfig, selfIp, null);
1022+
_networkMgr.savePlaceholderNic(guestConfig, selfIp, null, null);
10231023
} else {
10241024
// release the self-ip obtained from guest network
10251025
Nic selfipNic = getPlaceholderNic(guestConfig);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ Map<String, String> finalizeServicesAndProvidersForNetwork(NetworkOffering offer
381381

382382
String allocatePublicIpForGuestNic(Long networkId, DataCenter dc, Pod pod, Account caller, String requestedIp) throws InsufficientAddressCapacityException;
383383

384-
NicVO savePlaceholderNic(Network network, String ip4Address, Type vmType);
384+
NicVO savePlaceholderNic(Network network, String ip4Address, String ip6Address, Type vmType);
385385

386386
DhcpServiceProvider getDhcpServiceProvider(Network network);
387387

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4325,9 +4325,10 @@ public String allocatePublicIpForGuestNic(Long networkId, DataCenter dc, Pod pod
43254325

43264326

43274327
@Override
4328-
public NicVO savePlaceholderNic(Network network, String ip4Address, Type vmType) {
4328+
public NicVO savePlaceholderNic(Network network, String ip4Address, String ip6Address, Type vmType) {
43294329
NicVO nic = new NicVO(null, null, network.getId(), null);
43304330
nic.setIp4Address(ip4Address);
4331+
nic.setIp6Address(ip6Address);
43314332
nic.setReservationStrategy(ReservationStrategy.PlaceHolder);
43324333
nic.setState(Nic.State.Reserved);
43334334
nic.setVmType(vmType);

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,17 +2065,24 @@ public String getStartIpv6Address(long networkId) {
20652065
public NicVO getPlaceholderNicForRouter(Network network, Long podId) {
20662066
List<NicVO> nics = _nicDao.listPlaceholderNicsByNetworkIdAndVmType(network.getId(), VirtualMachine.Type.DomainRouter);
20672067
for (NicVO nic : nics) {
2068-
if (nic.getReserver() == null && nic.getIp4Address() != null) {
2068+
if (nic.getReserver() == null && (nic.getIp4Address() != null || nic.getIp6Address() != null)) {
20692069
if (podId == null) {
20702070
return nic;
20712071
} else {
20722072
//return nic only when its ip address belong to the pod range (for the Basic zone case)
20732073
List<? extends Vlan> vlans = _vlanDao.listVlansForPod(podId);
20742074
for (Vlan vlan : vlans) {
2075-
IpAddress ip = _ipAddressDao.findByIpAndNetworkId(network.getId(), nic.getIp4Address());
2076-
if (ip != null && ip.getVlanId() == vlan.getId()) {
2077-
return nic;
2078-
}
2075+
if (nic.getIp4Address() != null) {
2076+
IpAddress ip = _ipAddressDao.findByIpAndNetworkId(network.getId(), nic.getIp4Address());
2077+
if (ip != null && ip.getVlanId() == vlan.getId()) {
2078+
return nic;
2079+
}
2080+
} else {
2081+
UserIpv6AddressVO ipv6 = _ipv6Dao.findByNetworkIdAndIp(network.getId(), nic.getIp6Address());
2082+
if (ipv6 != null && ipv6.getVlanId() == vlan.getId()) {
2083+
return nic;
2084+
}
2085+
}
20792086
}
20802087
}
20812088
}

‎server/src/com/cloud/network/guru/DirectNetworkGuru.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,15 @@ protected void allocateDirectIp(NicProfile nic, Network network, VirtualMachineP
221221
throws InsufficientVirtualNetworkCapcityException,
222222
InsufficientAddressCapacityException {
223223

224-
//FIXME - save ipv6 informaiton in the placeholder nic
225224
Transaction txn = Transaction.currentTxn();
226225
txn.start();
227226
_networkMgr.allocateDirectIp(nic, dc, vm, network, requestedIp4Addr, requestedIp6Addr);
228227
//save the placeholder nic if the vm is the Virtual router
229228
if (vm.getType() == VirtualMachine.Type.DomainRouter) {
230229
Nic placeholderNic = _networkModel.getPlaceholderNicForRouter(network, null);
231230
if (placeholderNic == null) {
232-
s_logger.debug("Saving placeholder nic with ip4 address " + nic.getIp4Address() + " and ipv6 address " + requestedIp6Addr + " for the network " + network);
233-
_networkMgr.savePlaceholderNic(network, nic.getIp4Address(), VirtualMachine.Type.DomainRouter);
231+
s_logger.debug("Saving placeholder nic with ip4 address " + nic.getIp4Address() + " and ipv6 address " + nic.getIp6Address() + " for the network " + network);
232+
_networkMgr.savePlaceholderNic(network, nic.getIp4Address(), nic.getIp6Address(), VirtualMachine.Type.DomainRouter);
234233
}
235234
}
236235
txn.commit();

‎server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ protected void getIp(NicProfile nic, Pod pod, VirtualMachineProfile<? extends Vi
203203
Nic placeholderNic = _networkModel.getPlaceholderNicForRouter(network, pod.getId());
204204
if (placeholderNic == null) {
205205
s_logger.debug("Saving placeholder nic with ip4 address " + nic.getIp4Address() + " for the network " + network);
206-
_networkMgr.savePlaceholderNic(network, nic.getIp4Address(), VirtualMachine.Type.DomainRouter);
206+
_networkMgr.savePlaceholderNic(network, nic.getIp4Address(), null, VirtualMachine.Type.DomainRouter);
207207
}
208208
}
209209
txn.commit();

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

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,30 +1740,34 @@ protected List<Pair<NetworkVO, NicProfile>> createRouterNetworks(Account owner,
17401740
s_logger.debug("Adding nic for Virtual Router in Guest network " + guestNetwork);
17411741
String defaultNetworkStartIp = null, defaultNetworkStartIpv6 = null;
17421742
if (!setupPublicNetwork) {
1743+
Nic placeholder = _networkModel.getPlaceholderNicForRouter(guestNetwork, plan.getPodId());
17431744
if (guestNetwork.getCidr() != null) {
1744-
Nic placeholder = _networkModel.getPlaceholderNicForRouter(guestNetwork, plan.getPodId());
1745-
if (placeholder != null) {
1746-
s_logger.debug("Requesting ip address " + placeholder.getIp4Address() + " stored in placeholder nic for the network " + guestNetwork);
1747-
defaultNetworkStartIp = placeholder.getIp4Address();
1748-
} else {
1749-
String startIp = _networkModel.getStartIpAddress(guestNetwork.getId());
1750-
if (startIp != null && _ipAddressDao.findByIpAndSourceNetworkId(guestNetwork.getId(), startIp).getAllocatedTime() == null) {
1751-
defaultNetworkStartIp = startIp;
1752-
} else if (s_logger.isDebugEnabled()){
1753-
s_logger.debug("First ip " + startIp + " in network id=" + guestNetwork.getId() +
1754-
" is already allocated, can't use it for domain router; will get random ip address from the range");
1755-
}
1756-
}
1745+
if (placeholder != null && placeholder.getIp4Address() != null) {
1746+
s_logger.debug("Requesting ipv4 address " + placeholder.getIp4Address() + " stored in placeholder nic for the network " + guestNetwork);
1747+
defaultNetworkStartIp = placeholder.getIp4Address();
1748+
} else {
1749+
String startIp = _networkModel.getStartIpAddress(guestNetwork.getId());
1750+
if (startIp != null && _ipAddressDao.findByIpAndSourceNetworkId(guestNetwork.getId(), startIp).getAllocatedTime() == null) {
1751+
defaultNetworkStartIp = startIp;
1752+
} else if (s_logger.isDebugEnabled()){
1753+
s_logger.debug("First ipv4 " + startIp + " in network id=" + guestNetwork.getId() +
1754+
" is already allocated, can't use it for domain router; will get random ip address from the range");
1755+
}
1756+
}
17571757
}
1758-
1759-
//FIXME - get ipv6 stored in the placeholder
1758+
17601759
if (guestNetwork.getIp6Cidr() != null) {
1761-
String startIpv6 = _networkModel.getStartIpv6Address(guestNetwork.getId());
1762-
if (startIpv6 != null && _ipv6Dao.findByNetworkIdAndIp(guestNetwork.getId(), startIpv6) == null) {
1763-
defaultNetworkStartIpv6 = startIpv6;
1764-
} else if (s_logger.isDebugEnabled()){
1765-
s_logger.debug("First ipv6 " + startIpv6 + " in network id=" + guestNetwork.getId() +
1766-
" is already allocated, can't use it for domain router; will get random ipv6 address from the range");
1760+
if (placeholder != null && placeholder.getIp6Address() != null) {
1761+
s_logger.debug("Requesting ipv6 address " + placeholder.getIp6Address() + " stored in placeholder nic for the network " + guestNetwork);
1762+
defaultNetworkStartIpv6 = placeholder.getIp6Address();
1763+
} else {
1764+
String startIpv6 = _networkModel.getStartIpv6Address(guestNetwork.getId());
1765+
if (startIpv6 != null && _ipv6Dao.findByNetworkIdAndIp(guestNetwork.getId(), startIpv6) == null) {
1766+
defaultNetworkStartIpv6 = startIpv6;
1767+
} else if (s_logger.isDebugEnabled()){
1768+
s_logger.debug("First ipv6 " + startIpv6 + " in network id=" + guestNetwork.getId() +
1769+
" is already allocated, can't use it for domain router; will get random ipv6 address from the range");
1770+
}
17671771
}
17681772
}
17691773
}

‎server/test/com/cloud/network/MockNetworkManagerImpl.java‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,8 @@
6666
import com.cloud.user.User;
6767
import com.cloud.utils.Pair;
6868
import com.cloud.utils.component.ManagerBase;
69-
import com.cloud.vm.Nic;
70-
import com.cloud.vm.NicProfile;
71-
import com.cloud.vm.NicVO;
72-
import com.cloud.vm.ReservationContext;
73-
import com.cloud.vm.VMInstanceVO;
74-
import com.cloud.vm.VirtualMachine;
7569
import com.cloud.vm.*;
7670
import com.cloud.vm.VirtualMachine.Type;
77-
import com.cloud.vm.VirtualMachineProfile;
7871
import org.apache.cloudstack.api.command.admin.network.DedicateGuestVlanRangeCmd;
7972
import org.apache.cloudstack.api.command.admin.network.ListDedicatedGuestVlanRangesCmd;
8073
import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementorsCmd;
@@ -924,7 +917,7 @@ public String allocatePublicIpForGuestNic(Long networkId, DataCenter dc,
924917

925918

926919
@Override
927-
public NicVO savePlaceholderNic(Network network, String ip4Address, Type vmType) {
920+
public NicVO savePlaceholderNic(Network network, String ip4Address, String ip6Address, Type vmType) {
928921
// TODO Auto-generated method stub
929922
return null;
930923
}

‎server/test/com/cloud/vpc/MockNetworkManagerImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,7 @@ public String allocatePublicIpForGuestNic(Long networkId, DataCenter dc,
13931393

13941394

13951395
@Override
1396-
public NicVO savePlaceholderNic(Network network, String ip4Address, Type vmType) {
1396+
public NicVO savePlaceholderNic(Network network, String ip4Address, String ip6Address, Type vmType) {
13971397
// TODO Auto-generated method stub
13981398
return null;
13991399
}

0 commit comments

Comments
 (0)