mirror of https://github.com/apache/cloudstack.git
Merge branch '4.20' into 4.22
This commit is contained in:
commit
b5fd39fca0
|
|
@ -125,6 +125,10 @@ public interface NetworkModel {
|
||||||
*/
|
*/
|
||||||
String getNextAvailableMacAddressInNetwork(long networkConfigurationId) throws InsufficientAddressCapacityException;
|
String getNextAvailableMacAddressInNetwork(long networkConfigurationId) throws InsufficientAddressCapacityException;
|
||||||
|
|
||||||
|
String getUniqueMacAddress(long macAddress, long networkId, long datacenterId) throws InsufficientAddressCapacityException;
|
||||||
|
|
||||||
|
boolean isMACUnique(String mac, long networkId);
|
||||||
|
|
||||||
PublicIpAddress getPublicIpAddress(long ipAddressId);
|
PublicIpAddress getPublicIpAddress(long ipAddressId);
|
||||||
|
|
||||||
List<? extends Vlan> listPodVlans(long podId);
|
List<? extends Vlan> listPodVlans(long podId);
|
||||||
|
|
@ -364,4 +368,8 @@ public interface NetworkModel {
|
||||||
|
|
||||||
boolean checkSecurityGroupSupportForNetwork(Account account, DataCenter zone, List<Long> networkIds,
|
boolean checkSecurityGroupSupportForNetwork(Account account, DataCenter zone, List<Long> networkIds,
|
||||||
List<Long> securityGroupsIds);
|
List<Long> securityGroupsIds);
|
||||||
|
|
||||||
|
default long getMacIdentifier(Long dataCenterId) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,11 @@ public class PublicIp implements PublicIpAddress {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PublicIp createFromAddrAndVlan(IPAddressVO addr, VlanVO vlan) {
|
public static PublicIp createFromAddrAndVlan(IPAddressVO addr, VlanVO vlan) {
|
||||||
return new PublicIp(addr, vlan, NetUtils.createSequenceBasedMacAddress(addr.getMacAddress(), NetworkModel.MACIdentifier.value()));
|
long macIdentifier = NetworkModel.MACIdentifier.valueIn(addr.getDataCenterId());
|
||||||
|
if (macIdentifier == 0) {
|
||||||
|
macIdentifier = addr.getDataCenterId();
|
||||||
|
}
|
||||||
|
return new PublicIp(addr, vlan, NetUtils.createSequenceBasedMacAddress(addr.getMacAddress(), macIdentifier));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -279,5 +283,4 @@ public class PublicIp implements PublicIpAddress {
|
||||||
public boolean isForRouter() {
|
public boolean isForRouter() {
|
||||||
return _addr.isForRouter();
|
return _addr.isForRouter();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1283,7 +1283,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
|
||||||
nicProfile.setIPv4Gateway(ipv4Gateway);
|
nicProfile.setIPv4Gateway(ipv4Gateway);
|
||||||
nicProfile.setIPv4Netmask(ipv4Netmask);
|
nicProfile.setIPv4Netmask(ipv4Netmask);
|
||||||
|
|
||||||
if (nicProfile.getMacAddress() == null) {
|
if (nicProfile.getMacAddress() == null || !_networkModel.isMACUnique(nicProfile.getMacAddress(), network.getId())) {
|
||||||
try {
|
try {
|
||||||
String macAddress = _networkModel.getNextAvailableMacAddressInNetwork(network.getId());
|
String macAddress = _networkModel.getNextAvailableMacAddressInNetwork(network.getId());
|
||||||
nicProfile.setMacAddress(macAddress);
|
nicProfile.setMacAddress(macAddress);
|
||||||
|
|
|
||||||
|
|
@ -396,6 +396,7 @@ public class NetworkOrchestratorTest extends TestCase {
|
||||||
when(testOrchestrator._ipAddressDao.acquireInLockTable(Mockito.anyLong())).thenReturn(ipVoSpy);
|
when(testOrchestrator._ipAddressDao.acquireInLockTable(Mockito.anyLong())).thenReturn(ipVoSpy);
|
||||||
when(testOrchestrator._ipAddressDao.update(Mockito.anyLong(), Mockito.any(IPAddressVO.class))).thenReturn(true);
|
when(testOrchestrator._ipAddressDao.update(Mockito.anyLong(), Mockito.any(IPAddressVO.class))).thenReturn(true);
|
||||||
when(testOrchestrator._ipAddressDao.releaseFromLockTable(Mockito.anyLong())).thenReturn(true);
|
when(testOrchestrator._ipAddressDao.releaseFromLockTable(Mockito.anyLong())).thenReturn(true);
|
||||||
|
when(testOrchestrator._networkModel.isMACUnique(Mockito.anyString(), Mockito.anyLong())).thenReturn(true);
|
||||||
try {
|
try {
|
||||||
when(testOrchestrator._networkModel.getNextAvailableMacAddressInNetwork(Mockito.anyLong())).thenReturn(macAddress);
|
when(testOrchestrator._networkModel.getNextAvailableMacAddressInNetwork(Mockito.anyLong())).thenReturn(macAddress);
|
||||||
} catch (InsufficientAddressCapacityException e) {
|
} catch (InsufficientAddressCapacityException e) {
|
||||||
|
|
|
||||||
|
|
@ -462,8 +462,8 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long>implements Ne
|
||||||
public String getNextAvailableMacAddress(final long networkConfigId, Integer zoneMacIdentifier) {
|
public String getNextAvailableMacAddress(final long networkConfigId, Integer zoneMacIdentifier) {
|
||||||
final SequenceFetcher fetch = SequenceFetcher.getInstance();
|
final SequenceFetcher fetch = SequenceFetcher.getInstance();
|
||||||
long seq = fetch.getNextSequence(Long.class, _tgMacAddress, networkConfigId);
|
long seq = fetch.getNextSequence(Long.class, _tgMacAddress, networkConfigId);
|
||||||
if(zoneMacIdentifier != null && zoneMacIdentifier.intValue() != 0 ){
|
if (zoneMacIdentifier != null && zoneMacIdentifier != 0) {
|
||||||
seq = seq | _prefix << 40 | (long)zoneMacIdentifier << 32 | networkConfigId << 16 & 0x00000000ffff0000l;
|
seq = seq | _prefix << 40 | (long)zoneMacIdentifier << 32 | networkConfigId << 16 & 0x00000000ffff0000L;
|
||||||
}
|
}
|
||||||
return NetUtils.long2Mac(seq);
|
return NetUtils.long2Mac(seq);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ public interface NicDao extends GenericDao<NicVO, Long> {
|
||||||
|
|
||||||
List<NicVO> listByVmIdAndKeyword(long instanceId, String keyword);
|
List<NicVO> listByVmIdAndKeyword(long instanceId, String keyword);
|
||||||
|
|
||||||
NicVO findByMacAddress(String macAddress);
|
NicVO findByMacAddress(String macAddress, long networkId);
|
||||||
|
|
||||||
NicVO findByNetworkIdAndMacAddressIncludingRemoved(long networkId, String mac);
|
NicVO findByNetworkIdAndMacAddressIncludingRemoved(long networkId, String mac);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -420,9 +420,10 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NicVO findByMacAddress(String macAddress) {
|
public NicVO findByMacAddress(String macAddress, long networkId) {
|
||||||
SearchCriteria<NicVO> sc = AllFieldsSearch.create();
|
SearchCriteria<NicVO> sc = AllFieldsSearch.create();
|
||||||
sc.setParameters("macAddress", macAddress);
|
sc.setParameters("macAddress", macAddress);
|
||||||
|
sc.setParameters("network", networkId);
|
||||||
return findOneBy(sc);
|
return findOneBy(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -313,13 +313,8 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi
|
||||||
Math.min(CapacityManager.CapacityCalculateWorkers.value(), hostIds.size())));
|
Math.min(CapacityManager.CapacityCalculateWorkers.value(), hostIds.size())));
|
||||||
for (Long hostId : hostIds) {
|
for (Long hostId : hostIds) {
|
||||||
futures.put(hostId, executorService.submit(() -> {
|
futures.put(hostId, executorService.submit(() -> {
|
||||||
Transaction.execute(new TransactionCallbackNoReturn() {
|
final HostVO host = hostDao.findById(hostId);
|
||||||
@Override
|
_capacityMgr.updateCapacityForHost(host);
|
||||||
public void doInTransactionWithoutResult(TransactionStatus status) {
|
|
||||||
final HostVO host = hostDao.findById(hostId);
|
|
||||||
_capacityMgr.updateCapacityForHost(host);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return null;
|
return null;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2409,7 +2409,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
|
||||||
nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(ip.getVlanTag()));
|
nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(ip.getVlanTag()));
|
||||||
nic.setFormat(AddressFormat.Ip4);
|
nic.setFormat(AddressFormat.Ip4);
|
||||||
nic.setReservationId(String.valueOf(ip.getVlanTag()));
|
nic.setReservationId(String.valueOf(ip.getVlanTag()));
|
||||||
if(nic.getMacAddress() == null) {
|
if (nic.getMacAddress() == null) {
|
||||||
nic.setMacAddress(ip.getMacAddress());
|
nic.setMacAddress(ip.getMacAddress());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2460,7 +2460,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
|
||||||
|
|
||||||
nic.setBroadcastUri(network.getBroadcastUri());
|
nic.setBroadcastUri(network.getBroadcastUri());
|
||||||
nic.setFormat(AddressFormat.Ip4);
|
nic.setFormat(AddressFormat.Ip4);
|
||||||
if(nic.getMacAddress() == null) {
|
if (nic.getMacAddress() == null || !_networkModel.isMACUnique(nic.getMacAddress(), network.getId())) {
|
||||||
nic.setMacAddress(_networkModel.getNextAvailableMacAddressInNetwork(network.getId()));
|
nic.setMacAddress(_networkModel.getNextAvailableMacAddressInNetwork(network.getId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -241,7 +241,7 @@ public class Ipv6AddressManagerImpl extends ManagerBase implements Ipv6AddressMa
|
||||||
if (nic.getBroadCastUri() == null) {
|
if (nic.getBroadCastUri() == null) {
|
||||||
nic.setBroadcastUri(network.getBroadcastUri());
|
nic.setBroadcastUri(network.getBroadcastUri());
|
||||||
}
|
}
|
||||||
if (nic.getMacAddress() == null) {
|
if (nic.getMacAddress() == null || !_networkModel.isMACUnique(nic.getMacAddress(), network.getId())) {
|
||||||
nic.setMacAddress(_networkModel.getNextAvailableMacAddressInNetwork(network.getId()));
|
nic.setMacAddress(_networkModel.getNextAvailableMacAddressInNetwork(network.getId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -594,22 +594,34 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel, Confi
|
||||||
@Override
|
@Override
|
||||||
public String getNextAvailableMacAddressInNetwork(long networkId) throws InsufficientAddressCapacityException {
|
public String getNextAvailableMacAddressInNetwork(long networkId) throws InsufficientAddressCapacityException {
|
||||||
NetworkVO network = _networksDao.findById(networkId);
|
NetworkVO network = _networksDao.findById(networkId);
|
||||||
Integer zoneIdentifier = MACIdentifier.value();
|
if (network == null) {
|
||||||
if (zoneIdentifier.intValue() == 0) {
|
throw new CloudRuntimeException("Could not find network with id " + networkId);
|
||||||
zoneIdentifier = Long.valueOf(network.getDataCenterId()).intValue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Integer zoneMacIdentifier = Long.valueOf(getMacIdentifier(network.getDataCenterId())).intValue();
|
||||||
String mac;
|
String mac;
|
||||||
do {
|
do {
|
||||||
mac = _networksDao.getNextAvailableMacAddress(networkId, zoneIdentifier);
|
mac = _networksDao.getNextAvailableMacAddress(networkId, zoneMacIdentifier);
|
||||||
if (mac == null) {
|
if (mac == null) {
|
||||||
throw new InsufficientAddressCapacityException("Unable to create another mac address", Network.class, networkId);
|
throw new InsufficientAddressCapacityException("Unable to create another mac address", Network.class, networkId);
|
||||||
}
|
}
|
||||||
} while(! isMACUnique(mac));
|
} while (!isMACUnique(mac, networkId));
|
||||||
return mac;
|
return mac;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isMACUnique(String mac) {
|
@Override
|
||||||
return (_nicDao.findByMacAddress(mac) == null);
|
public String getUniqueMacAddress(long macAddress, long networkId, long datacenterId) throws InsufficientAddressCapacityException {
|
||||||
|
String macAddressStr = NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(macAddress, getMacIdentifier(datacenterId)));
|
||||||
|
if (!isMACUnique(macAddressStr, networkId)) {
|
||||||
|
macAddressStr = getNextAvailableMacAddressInNetwork(networkId);
|
||||||
|
}
|
||||||
|
return macAddressStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isMACUnique(String mac, long networkId) {
|
||||||
|
return (_nicDao.findByMacAddress(mac, networkId) == null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -2818,4 +2830,18 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel, Confi
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getMacIdentifier(Long dataCenterId) {
|
||||||
|
long macAddress = 0;
|
||||||
|
if (dataCenterId == null) {
|
||||||
|
macAddress = NetworkModel.MACIdentifier.value();
|
||||||
|
} else {
|
||||||
|
macAddress = NetworkModel.MACIdentifier.valueIn(dataCenterId);
|
||||||
|
if (macAddress == 0) {
|
||||||
|
macAddress = dataCenterId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return macAddress;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -293,7 +293,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
|
||||||
allocateDirectIp(nic, network, vm, dc, nic.getRequestedIPv4(), nic.getRequestedIPv6());
|
allocateDirectIp(nic, network, vm, dc, nic.getRequestedIPv4(), nic.getRequestedIPv6());
|
||||||
nic.setReservationStrategy(ReservationStrategy.Create);
|
nic.setReservationStrategy(ReservationStrategy.Create);
|
||||||
|
|
||||||
if (nic.getMacAddress() == null) {
|
if (nic.getMacAddress() == null || !_networkModel.isMACUnique(nic.getMacAddress(), network.getId())) {
|
||||||
nic.setMacAddress(_networkModel.getNextAvailableMacAddressInNetwork(network.getId()));
|
nic.setMacAddress(_networkModel.getNextAvailableMacAddressInNetwork(network.getId()));
|
||||||
if (nic.getMacAddress() == null) {
|
if (nic.getMacAddress() == null) {
|
||||||
throw new InsufficientAddressCapacityException("Unable to allocate more mac addresses", Network.class, network.getId());
|
throw new InsufficientAddressCapacityException("Unable to allocate more mac addresses", Network.class, network.getId());
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,8 @@ public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru {
|
||||||
DataCenterDao _dcDao;
|
DataCenterDao _dcDao;
|
||||||
@Inject
|
@Inject
|
||||||
StorageNetworkManager _sNwMgr;
|
StorageNetworkManager _sNwMgr;
|
||||||
|
@Inject
|
||||||
|
NetworkModel _networkModel;
|
||||||
|
|
||||||
Random _rand = new Random(System.currentTimeMillis());
|
Random _rand = new Random(System.currentTimeMillis());
|
||||||
|
|
||||||
|
|
@ -131,7 +133,8 @@ public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru {
|
||||||
Integer vlan = result.getVlan();
|
Integer vlan = result.getVlan();
|
||||||
|
|
||||||
nic.setIPv4Address(result.getIpAddress());
|
nic.setIPv4Address(result.getIpAddress());
|
||||||
nic.setMacAddress(NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(result.getMacAddress(), NetworkModel.MACIdentifier.value())));
|
String macAddress = _networkModel.getUniqueMacAddress(result.getMacAddress(), config.getId(), dest.getDataCenter().getId());
|
||||||
|
nic.setMacAddress(macAddress);
|
||||||
nic.setIPv4Gateway(pod.getGateway());
|
nic.setIPv4Gateway(pod.getGateway());
|
||||||
nic.setFormat(AddressFormat.Ip4);
|
nic.setFormat(AddressFormat.Ip4);
|
||||||
String netmask = NetUtils.getCidrNetmask(pod.getCidrSize());
|
String netmask = NetUtils.getCidrNetmask(pod.getCidrSize());
|
||||||
|
|
|
||||||
|
|
@ -189,8 +189,12 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru {
|
||||||
PrivateIpVO ipVO = _privateIpDao.allocateIpAddress(network.getDataCenterId(), network.getId(), null);
|
PrivateIpVO ipVO = _privateIpDao.allocateIpAddress(network.getDataCenterId(), network.getId(), null);
|
||||||
String vlanTag = BroadcastDomainType.getValue(network.getBroadcastUri());
|
String vlanTag = BroadcastDomainType.getValue(network.getBroadcastUri());
|
||||||
String netmask = NetUtils.getCidrNetmask(network.getCidr());
|
String netmask = NetUtils.getCidrNetmask(network.getCidr());
|
||||||
|
String macAddress = NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress(), networkModel.getMacIdentifier(network.getDataCenterId())));
|
||||||
|
if (!networkModel.isMACUnique(macAddress, network.getId())) {
|
||||||
|
macAddress = networkModel.getNextAvailableMacAddressInNetwork(network.getId());
|
||||||
|
}
|
||||||
PrivateIpAddress ip =
|
PrivateIpAddress ip =
|
||||||
new PrivateIpAddress(ipVO, vlanTag, network.getGateway(), netmask, NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress(), NetworkModel.MACIdentifier.value())));
|
new PrivateIpAddress(ipVO, vlanTag, network.getGateway(), netmask, macAddress);
|
||||||
|
|
||||||
nic.setIPv4Address(ip.getIpAddress());
|
nic.setIPv4Address(ip.getIpAddress());
|
||||||
nic.setIPv4Gateway(ip.getGateway());
|
nic.setIPv4Gateway(ip.getGateway());
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@ import com.cloud.network.dao.NetworkDao;
|
||||||
import com.cloud.network.dao.NetworkVO;
|
import com.cloud.network.dao.NetworkVO;
|
||||||
import com.cloud.offering.NetworkOffering;
|
import com.cloud.offering.NetworkOffering;
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
import com.cloud.utils.net.NetUtils;
|
|
||||||
import com.cloud.vm.Nic.ReservationStrategy;
|
import com.cloud.vm.Nic.ReservationStrategy;
|
||||||
import com.cloud.vm.NicProfile;
|
import com.cloud.vm.NicProfile;
|
||||||
import com.cloud.vm.ReservationContext;
|
import com.cloud.vm.ReservationContext;
|
||||||
|
|
@ -47,6 +46,8 @@ public class StorageNetworkGuru extends PodBasedNetworkGuru implements NetworkGu
|
||||||
@Inject
|
@Inject
|
||||||
StorageNetworkManager _sNwMgr;
|
StorageNetworkManager _sNwMgr;
|
||||||
@Inject
|
@Inject
|
||||||
|
NetworkModel _networkModel;
|
||||||
|
@Inject
|
||||||
NetworkDao _nwDao;
|
NetworkDao _nwDao;
|
||||||
|
|
||||||
protected StorageNetworkGuru() {
|
protected StorageNetworkGuru() {
|
||||||
|
|
@ -130,7 +131,8 @@ public class StorageNetworkGuru extends PodBasedNetworkGuru implements NetworkGu
|
||||||
|
|
||||||
vlan = ip.getVlan();
|
vlan = ip.getVlan();
|
||||||
nic.setIPv4Address(ip.getIpAddress());
|
nic.setIPv4Address(ip.getIpAddress());
|
||||||
nic.setMacAddress(NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ip.getMac(), NetworkModel.MACIdentifier.value())));
|
String macAddress = _networkModel.getUniqueMacAddress(ip.getMac(), network.getId(), dest.getDataCenter().getId());
|
||||||
|
nic.setMacAddress(macAddress);
|
||||||
nic.setFormat(AddressFormat.Ip4);
|
nic.setFormat(AddressFormat.Ip4);
|
||||||
nic.setIPv4Netmask(ip.getNetmask());
|
nic.setIPv4Netmask(ip.getNetmask());
|
||||||
nic.setBroadcastType(BroadcastDomainType.Storage);
|
nic.setBroadcastType(BroadcastDomainType.Storage);
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
// under the License.
|
// under the License.
|
||||||
package com.cloud.network.router;
|
package com.cloud.network.router;
|
||||||
|
|
||||||
|
import com.cloud.exception.InsufficientAddressCapacityException;
|
||||||
import org.apache.cloudstack.network.router.deployment.RouterDeploymentDefinition;
|
import org.apache.cloudstack.network.router.deployment.RouterDeploymentDefinition;
|
||||||
|
|
||||||
import com.cloud.network.Network;
|
import com.cloud.network.Network;
|
||||||
|
|
@ -24,7 +25,7 @@ import com.cloud.vm.NicProfile;
|
||||||
|
|
||||||
public interface NicProfileHelper {
|
public interface NicProfileHelper {
|
||||||
|
|
||||||
public abstract NicProfile createPrivateNicProfileForGateway(final VpcGateway privateGateway, final VirtualRouter router);
|
public abstract NicProfile createPrivateNicProfileForGateway(final VpcGateway privateGateway, final VirtualRouter router) throws InsufficientAddressCapacityException;
|
||||||
|
|
||||||
public abstract NicProfile createGuestNicProfileForVpcRouter(final RouterDeploymentDefinition vpcRouterDeploymentDefinition,
|
public abstract NicProfile createGuestNicProfileForVpcRouter(final RouterDeploymentDefinition vpcRouterDeploymentDefinition,
|
||||||
Network guestNetwork);
|
Network guestNetwork);
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import java.net.URI;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import com.cloud.exception.InsufficientAddressCapacityException;
|
||||||
import com.cloud.vm.NicVO;
|
import com.cloud.vm.NicVO;
|
||||||
import com.cloud.vm.VirtualMachine;
|
import com.cloud.vm.VirtualMachine;
|
||||||
import org.apache.cloudstack.network.router.deployment.RouterDeploymentDefinition;
|
import org.apache.cloudstack.network.router.deployment.RouterDeploymentDefinition;
|
||||||
|
|
@ -61,7 +62,7 @@ public class NicProfileHelperImpl implements NicProfileHelper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@DB
|
@DB
|
||||||
public NicProfile createPrivateNicProfileForGateway(final VpcGateway privateGateway, final VirtualRouter router) {
|
public NicProfile createPrivateNicProfileForGateway(final VpcGateway privateGateway, final VirtualRouter router) throws InsufficientAddressCapacityException {
|
||||||
final Network privateNetwork = _networkModel.getNetwork(privateGateway.getNetworkId());
|
final Network privateNetwork = _networkModel.getNetwork(privateGateway.getNetworkId());
|
||||||
|
|
||||||
PrivateIpVO ipVO = _privateIpDao.allocateIpAddress(privateNetwork.getDataCenterId(), privateNetwork.getId(), privateGateway.getIp4Address());
|
PrivateIpVO ipVO = _privateIpDao.allocateIpAddress(privateNetwork.getDataCenterId(), privateNetwork.getId(), privateGateway.getIp4Address());
|
||||||
|
|
@ -90,14 +91,14 @@ public class NicProfileHelperImpl implements NicProfileHelper {
|
||||||
privateNicProfile.setDeviceId(null);
|
privateNicProfile.setDeviceId(null);
|
||||||
|
|
||||||
if (router.getIsRedundantRouter()) {
|
if (router.getIsRedundantRouter()) {
|
||||||
String newMacAddress = NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress(), NetworkModel.MACIdentifier.value()));
|
String newMacAddress = _networkModel.getUniqueMacAddress(ipVO.getMacAddress(), privateNetwork.getId(), privateNetwork.getDataCenterId());
|
||||||
privateNicProfile.setMacAddress(newMacAddress);
|
privateNicProfile.setMacAddress(newMacAddress);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final String netmask = NetUtils.getCidrNetmask(privateNetwork.getCidr());
|
final String netmask = NetUtils.getCidrNetmask(privateNetwork.getCidr());
|
||||||
|
String newMacAddress = _networkModel.getUniqueMacAddress(ipVO.getMacAddress(), privateNetwork.getId(), privateNetwork.getDataCenterId());
|
||||||
final PrivateIpAddress ip =
|
final PrivateIpAddress ip =
|
||||||
new PrivateIpAddress(ipVO, privateNetwork.getBroadcastUri().toString(), privateNetwork.getGateway(), netmask,
|
new PrivateIpAddress(ipVO, privateNetwork.getBroadcastUri().toString(), privateNetwork.getGateway(), netmask, newMacAddress);
|
||||||
NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress(), NetworkModel.MACIdentifier.value())));
|
|
||||||
|
|
||||||
final URI netUri = BroadcastDomainType.fromString(ip.getBroadcastUri());
|
final URI netUri = BroadcastDomainType.fromString(ip.getBroadcastUri());
|
||||||
privateNicProfile.setIPv4Address(ip.getIpAddress());
|
privateNicProfile.setIPv4Address(ip.getIpAddress());
|
||||||
|
|
|
||||||
|
|
@ -246,8 +246,10 @@ public class Ipv6AddressManagerTest {
|
||||||
|
|
||||||
Mockito.when(network.getIp6Cidr()).thenReturn("2001:db8:100::/64");
|
Mockito.when(network.getIp6Cidr()).thenReturn("2001:db8:100::/64");
|
||||||
Mockito.when(network.getIp6Gateway()).thenReturn("2001:db8:100::1");
|
Mockito.when(network.getIp6Gateway()).thenReturn("2001:db8:100::1");
|
||||||
|
Mockito.when(network.getId()).thenReturn(1L);
|
||||||
|
|
||||||
Mockito.when(networkModel.getNetworkIp6Dns(network, dc)).thenReturn(new Pair<>("2001:db8::53:1", "2001:db8::53:2"));
|
Mockito.when(networkModel.getNetworkIp6Dns(network, dc)).thenReturn(new Pair<>("2001:db8::53:1", "2001:db8::53:2"));
|
||||||
|
Mockito.when(networkModel.isMACUnique("1e:00:b1:00:0a:f6", 1L)).thenReturn(true);
|
||||||
|
|
||||||
String expected = "2001:db8:100:0:1c00:b1ff:fe00:af6";
|
String expected = "2001:db8:100:0:1c00:b1ff:fe00:af6";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,24 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see com.cloud.network.NetworkModel#getUniqueMacAddress(long, long, long)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getUniqueMacAddress(long macAddress, long networkId, long datacenterId) throws InsufficientAddressCapacityException {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see com.cloud.network.NetworkModel#isMACUnique(String, long)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isMACUnique(String mac, long networkId) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see com.cloud.network.NetworkModel#getPublicIpAddress(long)
|
* @see com.cloud.network.NetworkModel#getPublicIpAddress(long)
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -141,6 +141,24 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see com.cloud.network.NetworkModel#getUniqueMacAddress(long, long, long)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getUniqueMacAddress(long macAddress, long networkId, long datacenterId) throws InsufficientAddressCapacityException {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see com.cloud.network.NetworkModel#isMACUnique(String, long)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isMACUnique(String mac, long networkId) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see com.cloud.network.NetworkModel#getPublicIpAddress(long)
|
* @see com.cloud.network.NetworkModel#getPublicIpAddress(long)
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -184,49 +184,29 @@ stop_start_system() {
|
||||||
stop_start_router() {
|
stop_start_router() {
|
||||||
prepare_ids_clause
|
prepare_ids_clause
|
||||||
router=(`mysql -h $db --user=$user --password=$password --skip-column-names -U cloud -e "select uuid from vm_instance where state=\"Running\" and type=\"DomainRouter\"$zone$vmidsclause"`)
|
router=(`mysql -h $db --user=$user --password=$password --skip-column-names -U cloud -e "select uuid from vm_instance where state=\"Running\" and type=\"DomainRouter\"$zone$vmidsclause"`)
|
||||||
length_router=(${#router[@]})
|
length_router=${#router[@]}
|
||||||
|
|
||||||
echo -e "\nStopping and starting $length_router running routing vm(s)$inzone$withids... "
|
echo -e "\nStopping and starting $length_router running routing vm(s)$inzone$withids... "
|
||||||
echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Stopping and starting $length_router running routing vm(s)$inzone$withids... " >>$LOGFILE
|
echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Stopping and starting $length_router running routing vm(s)$inzone$withids... " >>$LOGFILE
|
||||||
|
|
||||||
#Spawn reboot router in parallel - run commands in <n> chunks - number of threads is configurable
|
#Spawn reboot router in parallel - run commands in <n> chunks - number of threads is configurable
|
||||||
|
|
||||||
|
if [ $maxthreads -gt $length_router ]; then
|
||||||
|
maxthreads=$length_router
|
||||||
|
fi
|
||||||
pids=()
|
pids=()
|
||||||
for d in "${router[@]}"; do
|
for d in "${router[@]}"; do
|
||||||
|
|
||||||
reboot_router $d &
|
reboot_router $d &
|
||||||
|
|
||||||
pids=( "${pids[@]}" $! )
|
pids=( "${pids[@]}" $! )
|
||||||
|
length_pids=${#pids[@]}
|
||||||
length_pids=(${#pids[@]})
|
|
||||||
unfinishedPids=(${#pids[@]})
|
|
||||||
|
|
||||||
if [ $maxthreads -gt $length_router ]; then
|
|
||||||
maxthreads=$length_router
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $length_pids -ge $maxthreads ]; then
|
if [ $length_pids -ge $maxthreads ]; then
|
||||||
while [ $unfinishedPids -gt 0 ]; do
|
# Wait for $maxthreads number of processes to finish
|
||||||
sleep 10
|
wait
|
||||||
count=0
|
# Clear the pids array for the next batch
|
||||||
for (( i = 0 ; i < $length_pids; i++ )); do
|
pids=()
|
||||||
if ! ps ax | grep -v grep | grep ${pids[$i]} > /dev/null; then
|
|
||||||
count=`expr $count + 1`
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ $count -eq $unfinishedPids ]; then
|
|
||||||
unfinishedPids=0
|
|
||||||
fi
|
|
||||||
|
|
||||||
done
|
|
||||||
|
|
||||||
#remove all elements from pids
|
|
||||||
if [ $unfinishedPids -eq 0 ]; then
|
|
||||||
pids=()
|
|
||||||
length_pids=(${#pids[@]})
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
@ -234,9 +214,8 @@ stop_start_router() {
|
||||||
if [ "$length_router" == "0" ];then
|
if [ "$length_router" == "0" ];then
|
||||||
echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] No running router vms found \n" >>$LOGFILE
|
echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] No running router vms found \n" >>$LOGFILE
|
||||||
else
|
else
|
||||||
while [ $unfinishedPids -gt 0 ]; do
|
# Wait for the remaining background processes to finish
|
||||||
sleep 10
|
wait
|
||||||
done
|
|
||||||
|
|
||||||
echo -e "Done restarting router(s)$inzone$withids. \n"
|
echo -e "Done restarting router(s)$inzone$withids. \n"
|
||||||
echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Done restarting router(s)$inzone$withids. \n" >>$LOGFILE
|
echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Done restarting router(s)$inzone$withids. \n" >>$LOGFILE
|
||||||
|
|
@ -288,49 +267,29 @@ reboot_router(){
|
||||||
restart_networks(){
|
restart_networks(){
|
||||||
networks=(`mysql -h $db --user=$user --password=$password --skip-column-names -U cloud -e "select n.id
|
networks=(`mysql -h $db --user=$user --password=$password --skip-column-names -U cloud -e "select n.id
|
||||||
from networks n, network_offerings no where n.network_offering_id = no.id and no.system_only = 0 and n.removed is null$zone"`)
|
from networks n, network_offerings no where n.network_offering_id = no.id and no.system_only = 0 and n.removed is null$zone"`)
|
||||||
length_networks=(${#networks[@]})
|
length_networks=${#networks[@]}
|
||||||
|
|
||||||
echo -e "\nRestarting $length_networks networks$inzone... "
|
echo -e "\nRestarting $length_networks networks$inzone... "
|
||||||
echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Restarting $length_networks networks$inzone... " >>$LOGFILE
|
echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Restarting $length_networks networks$inzone... " >>$LOGFILE
|
||||||
|
|
||||||
#Spawn restart network in parallel - run commands in <n> chunks - number of threads is configurable
|
#Spawn restart network in parallel - run commands in <n> chunks - number of threads is configurable
|
||||||
|
|
||||||
|
if [ $maxthreads -gt $length_networks ]; then
|
||||||
|
maxthreads=$length_networks
|
||||||
|
fi
|
||||||
pids=()
|
pids=()
|
||||||
for d in "${networks[@]}"; do
|
for d in "${networks[@]}"; do
|
||||||
|
|
||||||
restart_network $d &
|
restart_network $d &
|
||||||
|
|
||||||
pids=( "${pids[@]}" $! )
|
pids=( "${pids[@]}" $! )
|
||||||
|
length_pids=${#pids[@]}
|
||||||
length_pids=(${#pids[@]})
|
|
||||||
unfinishedPids=(${#pids[@]})
|
|
||||||
|
|
||||||
if [ $maxthreads -gt $length_networks ]; then
|
|
||||||
maxthreads=$length_networks
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $length_pids -ge $maxthreads ]; then
|
if [ $length_pids -ge $maxthreads ]; then
|
||||||
while [ $unfinishedPids -gt 0 ]; do
|
# Wait for $maxthreads number of processes to finish
|
||||||
sleep 10
|
wait
|
||||||
count=0
|
# Clear the pids array for the next batch
|
||||||
for (( i = 0 ; i < $length_pids; i++ )); do
|
pids=()
|
||||||
if ! ps ax | grep -v grep | grep ${pids[$i]} > /dev/null; then
|
|
||||||
count=`expr $count + 1`
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ $count -eq $unfinishedPids ]; then
|
|
||||||
unfinishedPids=0
|
|
||||||
fi
|
|
||||||
|
|
||||||
done
|
|
||||||
|
|
||||||
#remove all elements from pids
|
|
||||||
if [ $unfinishedPids -eq 0 ]; then
|
|
||||||
pids=()
|
|
||||||
length_pids=(${#pids[@]})
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
@ -339,9 +298,8 @@ restart_networks(){
|
||||||
if [ "$length_networks" == "0" ];then
|
if [ "$length_networks" == "0" ];then
|
||||||
echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] No networks found \n" >>$LOGFILE
|
echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] No networks found \n" >>$LOGFILE
|
||||||
else
|
else
|
||||||
while [ $unfinishedPids -gt 0 ]; do
|
# Wait for the remaining background processes to finish
|
||||||
sleep 10
|
wait
|
||||||
done
|
|
||||||
|
|
||||||
echo -e "Done restarting networks$inzone. \n"
|
echo -e "Done restarting networks$inzone. \n"
|
||||||
echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Done restarting networks$inzone. \n" >>$LOGFILE
|
echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Done restarting networks$inzone. \n" >>$LOGFILE
|
||||||
|
|
@ -392,49 +350,29 @@ restart_vpc(){
|
||||||
|
|
||||||
restart_vpcs(){
|
restart_vpcs(){
|
||||||
vpcs=(`mysql -h $db --user=$user --password=$password --skip-column-names -U cloud -e "select uuid from vpc WHERE removed is null$zone"`)
|
vpcs=(`mysql -h $db --user=$user --password=$password --skip-column-names -U cloud -e "select uuid from vpc WHERE removed is null$zone"`)
|
||||||
length_vpcs=(${#vpcs[@]})
|
length_vpcs=${#vpcs[@]}
|
||||||
|
|
||||||
echo -e "\nRestarting $length_vpcs vpcs... "
|
echo -e "\nRestarting $length_vpcs vpcs... "
|
||||||
echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Restarting $length_vpcs vpcs... " >>$LOGFILE
|
echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Restarting $length_vpcs vpcs... " >>$LOGFILE
|
||||||
|
|
||||||
#Spawn restart vpcs in parallel - run commands in <n> chunks - number of threads is configurable
|
#Spawn restart vpcs in parallel - run commands in <n> chunks - number of threads is configurable
|
||||||
|
|
||||||
|
if [ $maxthreads -gt $length_vpcs ]; then
|
||||||
|
maxthreads=$length_vpcs
|
||||||
|
fi
|
||||||
pids=()
|
pids=()
|
||||||
for d in "${vpcs[@]}"; do
|
for d in "${vpcs[@]}"; do
|
||||||
|
|
||||||
restart_vpc $d &
|
restart_vpc $d &
|
||||||
|
|
||||||
pids=( "${pids[@]}" $! )
|
pids=( "${pids[@]}" $! )
|
||||||
|
length_pids=${#pids[@]}
|
||||||
length_pids=(${#pids[@]})
|
|
||||||
unfinishedPids=(${#pids[@]})
|
|
||||||
|
|
||||||
if [ $maxthreads -gt $length_vpcs ]; then
|
|
||||||
maxthreads=$length_vpcs
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $length_pids -ge $maxthreads ]; then
|
if [ $length_pids -ge $maxthreads ]; then
|
||||||
while [ $unfinishedPids -gt 0 ]; do
|
# Wait for $maxthreads number of processes to finish
|
||||||
sleep 10
|
wait
|
||||||
count=0
|
# Clear the pids array for the next batch
|
||||||
for (( i = 0 ; i < $length_pids; i++ )); do
|
pids=()
|
||||||
if ! ps ax | grep -v grep | grep ${pids[$i]} > /dev/null; then
|
|
||||||
count=`expr $count + 1`
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ $count -eq $unfinishedPids ]; then
|
|
||||||
unfinishedPids=0
|
|
||||||
fi
|
|
||||||
|
|
||||||
done
|
|
||||||
|
|
||||||
#remove all elements from pids
|
|
||||||
if [ $unfinishedPids -eq 0 ]; then
|
|
||||||
pids=()
|
|
||||||
length_pids=(${#pids[@]})
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
@ -443,9 +381,8 @@ restart_vpcs(){
|
||||||
if [ "$length_vpcs" == "0" ];then
|
if [ "$length_vpcs" == "0" ];then
|
||||||
echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] No vpcs found \n" >>$LOGFILE
|
echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] No vpcs found \n" >>$LOGFILE
|
||||||
else
|
else
|
||||||
while [ $unfinishedPids -gt 0 ]; do
|
# Wait for the remaining background processes to finish
|
||||||
sleep 10
|
wait
|
||||||
done
|
|
||||||
|
|
||||||
echo -e "Done restarting vpcs$inzone. \n"
|
echo -e "Done restarting vpcs$inzone. \n"
|
||||||
echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Done restarting vpcs$inzone. \n" >>$LOGFILE
|
echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Done restarting vpcs$inzone. \n" >>$LOGFILE
|
||||||
|
|
|
||||||
|
|
@ -131,17 +131,17 @@ public class NetUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long createSequenceBasedMacAddress(final long macAddress, long globalConfig) {
|
public static long createSequenceBasedMacAddress(final long macAddress, long macIdentifier) {
|
||||||
/*
|
/*
|
||||||
Logic for generating MAC address:
|
Logic for generating MAC address:
|
||||||
Mac = B1:B2:B3:B4:B5:B6 (Bx is a byte).
|
Mac = B1:B2:B3:B4:B5:B6 (Bx is a byte).
|
||||||
B1 -> Presently controlled by prefix variable. The value should be such that the MAC is local and unicast.
|
B1 -> Presently controlled by prefix variable. The value should be such that the MAC is local and unicast.
|
||||||
B2 -> This will be configurable for each deployment/installation. Controlled by the global config MACIdentifier
|
B2 -> This will be configurable for each deployment/installation. Controlled by the 'mac.identifier' zone-level config
|
||||||
B3 -> A randomly generated number between 0 - 255
|
B3 -> A randomly generated number between 0 - 255
|
||||||
B4,5,6 -> These bytes are based on the unique DB identifier associated with the IP address for which MAC is generated (refer to mac_address field in user_ip_address table).
|
B4,5,6 -> These bytes are based on the unique DB identifier associated with the IP address for which MAC is generated (refer to mac_address field in user_ip_address table).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return macAddress | prefix<<40 | globalConfig << 32 & 0x00ff00000000l | (long)s_rand.nextInt(255) << 24;
|
return macAddress | prefix << 40 | macIdentifier << 32 & 0x00ff00000000L | (long)s_rand.nextInt(255) << 24;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getHostName() {
|
public static String getHostName() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue