Skip to content

Routed: support vxlan networks #10861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: 4.20
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
network.setBroadcastUri(BroadcastDomainType.Vxlan.toUri(vxlan));
}
network.setBroadcastDomainType(BroadcastDomainType.Vxlan);

getOrCreateIpv4SubnetForGuestNetwork(offering, network, userSpecified, owner);

return updateNetworkDesignForIPv6IfNeeded(network, userSpecified);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import org.apache.cloudstack.api.ApiCommandResourceType;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import org.apache.cloudstack.network.Ipv4GuestSubnetNetworkMap;
import org.apache.cloudstack.network.RoutedIpv4Manager;

import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenter.NetworkType;
Expand All @@ -37,7 +35,6 @@
import com.cloud.event.EventVO;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientVirtualNetworkCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.network.IpAddressManager;
import com.cloud.network.Network;
import com.cloud.network.Network.GuestType;
Expand Down Expand Up @@ -90,8 +87,6 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru {
FirewallRulesDao _fwRulesDao;
@Inject
FirewallRulesCidrsDao _fwRulesCidrDao;
@Inject
RoutedIpv4Manager routedIpv4Manager;

public ExternalGuestNetworkGuru() {
super();
Expand Down Expand Up @@ -126,23 +121,9 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
/* In order to revert userSpecified network setup */
config.setState(State.Allocated);
}
if (NetworkOffering.NetworkMode.ROUTED.equals(offering.getNetworkMode()) && !offering.isForVpc()) {
if (userSpecified.getCidr() != null) {
routedIpv4Manager.getOrCreateIpv4SubnetForGuestNetwork(config, userSpecified.getCidr());
} else {
if (userSpecified.getNetworkCidrSize() == null) {
throw new InvalidParameterValueException("The network CIDR or CIDR size must be specified.");
}
Ipv4GuestSubnetNetworkMap subnet = routedIpv4Manager.getOrCreateIpv4SubnetForGuestNetwork(owner.getDomainId(), owner.getAccountId(), config.getDataCenterId(), userSpecified.getNetworkCidrSize());
if (subnet != null) {
final String[] cidrTuple = subnet.getSubnet().split("\\/");
config.setGateway(NetUtils.getIpRangeStartIpFromCidr(cidrTuple[0], Long.parseLong(cidrTuple[1])));
config.setCidr(subnet.getSubnet());
} else {
throw new InvalidParameterValueException("Failed to allocate a CIDR with requested size.");
}
}
}

getOrCreateIpv4SubnetForGuestNetwork(offering, config, userSpecified, owner);

return updateNetworkDesignForIPv6IfNeeded(config, userSpecified);
}

Expand Down
24 changes: 24 additions & 0 deletions server/src/main/java/com/cloud/network/guru/GuestNetworkGuru.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.Configurable;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.network.Ipv4GuestSubnetNetworkMap;
import org.apache.cloudstack.network.RoutedIpv4Manager;
import org.apache.commons.lang3.StringUtils;

import com.cloud.configuration.Config;
Expand Down Expand Up @@ -121,6 +123,8 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
Ipv6AddressManager ipv6AddressManager;
@Inject
DomainRouterDao domainRouterDao;
@Inject
RoutedIpv4Manager routedIpv4Manager;

Random _rand = new Random(System.currentTimeMillis());

Expand Down Expand Up @@ -571,4 +575,24 @@ public Network updateNetworkDesignForIPv6IfNeeded(NetworkVO network, Network use
}
return network;
}

public void getOrCreateIpv4SubnetForGuestNetwork(NetworkOffering offering, NetworkVO config, Network userSpecified, Account owner) {
if (NetworkOffering.NetworkMode.ROUTED.equals(offering.getNetworkMode()) && !offering.isForVpc()) {
if (userSpecified.getCidr() != null) {
routedIpv4Manager.getOrCreateIpv4SubnetForGuestNetwork(config, userSpecified.getCidr());
} else {
if (userSpecified.getNetworkCidrSize() == null) {
throw new InvalidParameterValueException("The network CIDR or CIDR size must be specified.");
}
Ipv4GuestSubnetNetworkMap subnet = routedIpv4Manager.getOrCreateIpv4SubnetForGuestNetwork(owner.getDomainId(), owner.getAccountId(), config.getDataCenterId(), userSpecified.getNetworkCidrSize());
if (subnet != null) {
final String[] cidrTuple = subnet.getSubnet().split("\\/");
config.setGateway(NetUtils.getIpRangeStartIpFromCidr(cidrTuple[0], Long.parseLong(cidrTuple[1])));
config.setCidr(subnet.getSubnet());
} else {
throw new InvalidParameterValueException("Failed to allocate a CIDR with requested size.");
}
}
}
}
}
Loading