Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
01889e2
Rename nsx mode to routing mode
weizhouapache Apr 29, 2024
0dc01b6
ROUTED mode: add network/vpc offerings
weizhouapache May 24, 2024
d496af0
Routed v8
weizhouapache May 25, 2024
c922a62
Routed v10
weizhouapache May 28, 2024
fa1918e
Routed v11
weizhouapache May 29, 2024
83e87a3
Routed v12
weizhouapache May 30, 2024
df8069d
Routed v13
weizhouapache May 31, 2024
b676317
Routed v14
weizhouapache May 31, 2024
946b618
Routed v15
weizhouapache Jun 7, 2024
9b22a31
Routed v16
weizhouapache Jun 8, 2024
7d8413d
Routed 21
weizhouapache Jun 18, 2024
1bbb16c
Routed 22
weizhouapache Jun 19, 2024
17f183e
Routed v23
weizhouapache Jun 20, 2024
6d44747
Routed v24
weizhouapache Jun 22, 2024
3ba853d
Routed v25
weizhouapache Jun 24, 2024
6a8bec2
Routed v26: implement subnet auto-allocation
weizhouapache Jun 25, 2024
77fa42d
Routed 27: add subnet for VPC
weizhouapache Jun 25, 2024
522e3a1
Routed v28: update smoke tests
weizhouapache Jun 25, 2024
fb3f3bf
Routed 29: fix vpc and add more tests
weizhouapache Jun 26, 2024
2db0192
Routed 31: ui and smoke tests
weizhouapache Jun 27, 2024
db9dea3
Routed 32: add chain OUTPUT and more rules
weizhouapache Jun 28, 2024
9387aef
Routed: fix dns search from VMs in Isolated networks
weizhouapache Jul 3, 2024
a6f7876
Routed: fix VPC dns issue due to gateway IP is missing in cloud.conf
weizhouapache Jul 3, 2024
648dcae
Routed: rename routing_mode to network_mode
weizhouapache Jul 4, 2024
42842c6
Routed: replace centos5.5 template in smoke test as dhclient does not…
weizhouapache Jul 4, 2024
a1b0b64
Routed: fix smoke test due to wrong cidrlist of egress rules and miss…
weizhouapache Jul 5, 2024
57de7cc
PR 9346: fix lint error schema-41910to42000.sql
weizhouapache Jul 5, 2024
27a2005
PR 9346: ui polish v1
weizhouapache Jul 5, 2024
9397b8d
PR 9346: create VPC with cidrsize
weizhouapache Jul 5, 2024
b8e3950
Routed: fix test failures with test_network_ipv6 and test_vpc_ipv6 du…
weizhouapache Jul 8, 2024
532319f
Routed: fix /usr/local/cloud/systemvm/ are removed after SSVM/CPVM re…
weizhouapache Jul 8, 2024
40c12bf
Routed: fix IP of additional nics of VPC VR is not gateway
weizhouapache Jul 8, 2024
720f57e
Merge remote-tracking branch 'apache/main' into 4.20-routed-mode
weizhouapache Jul 8, 2024
a599950
PR 9346: fix cidrsize check when create VPC with cidrsize
weizhouapache Jul 8, 2024
ef70262
Routed: fix test/integration/smoke/test_ipv4_routing.py:279:16: E713 …
weizhouapache Jul 8, 2024
5b77f02
Merge remote-tracking branch 'apache/main' into 4.20-routed-mode
weizhouapache Jul 9, 2024
e493196
Merge remote-tracking branch 'apache/main' into 4.20-routed-mode
weizhouapache Jul 12, 2024
c04bfb4
PR9346: fix/Update api
weizhouapache Jul 12, 2024
4579b49
PR 9346: set response object name
weizhouapache Jul 12, 2024
3763fd2
PR9346: UI refactor and small fixes
weizhouapache Jul 12, 2024
fd88a9e
Merge remote-tracking branch 'apache/main' into 4.20-routed-mode
weizhouapache Jul 14, 2024
21d52ec
PR9346: change return type of getNetworkMode
weizhouapache Jul 15, 2024
0795237
Merge remote-tracking branch 'apache/main' into 4.20-routed-mode
weizhouapache Jul 16, 2024
6d52a64
PR9346: move IPv4 subnet to seperated tab
weizhouapache Jul 13, 2024
f156f59
PR9346: revert IpRangesTabGuest.vue back to original
weizhouapache Jul 16, 2024
8901ddd
Merge remote-tracking branch 'apache/main' into 4.20-routed-mode
weizhouapache Jul 17, 2024
798074b
PR9346: fix remove ipv4 subnet on UI
weizhouapache Jul 17, 2024
bf21ff4
PR9346: fix test_ipv4_routing.py
weizhouapache Jul 17, 2024
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
Prev Previous commit
Next Next commit
Routed 27: add subnet for VPC
- add db column for vpc_id
- add db record for vpc
- remove db record when delete a vpc
- add checkConflicts methods
- remove duplicated settings
- check ipv4 cidr when create subnet
  • Loading branch information
weizhouapache committed Jul 5, 2024
commit 77fa42dd49ca26ac2c6414d09f3f221a44de833c
8 changes: 0 additions & 8 deletions api/src/main/java/com/cloud/network/NetworkService.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,6 @@ public interface NetworkService {
"allow.end.users.to.specify.vr.mtu", "false", "Allow end users to specify VR MTU",
true, ConfigKey.Scope.Zone);

ConfigKey<Integer> RoutedIPv4NetworkMaxCidrSize = new ConfigKey<>("Network", Integer.class,
"routed.ipv4.network.max.cidr.size", "32", "The maximum value of the cidr size for isolated networks in ROUTED mode",
true, ConfigKey.Scope.Zone);

ConfigKey<Integer> RoutedIPv4NetworkMinCidrSize = new ConfigKey<>("Network", Integer.class,
"routed.ipv4.network.min.cidr.size", "24", "The minimum value of the cidr size for isolated networks in ROUTED mode",
true, ConfigKey.Scope.Zone);

List<? extends Network> getIsolatedNetworksOwnedByAccountInZone(long zoneId, Account owner);

IpAddress allocateIP(Account ipOwner, long zoneId, Long networkId, Boolean displayIp, String ipaddress) throws ResourceAllocationException, InsufficientAddressCapacityException,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public class Ipv4SubnetForGuestNetworkResponse extends BaseResponse {
@Param(description = "subnet of the IPv4 network")
private String subnet;

@SerializedName(ApiConstants.STATE)
@Param(description = "state of subnet of the IPv4 network")
private String state;

@SerializedName(ApiConstants.ZONE_ID)
@Param(description = "id of zone to which the IPv4 subnet belongs to." )
private String zoneId;
Expand Down Expand Up @@ -89,6 +93,10 @@ public void setSubnet(String subnet) {
this.subnet = subnet;
}

public void setState(String state) {
this.state = state;
}

public void setNetworkId(String networkId) {
this.networkId = networkId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ enum State {

String getSubnet();

Long getVpcId();

Long getNetworkId();

State getState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,16 @@

public interface RoutedIpv4Manager extends PluggableService, Configurable {

ConfigKey<Integer> RoutedNetworkMaxCidrSize = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, Integer.class,
"routed.network.max.cidr.size",
"30",
"The maximum cidr size of routed network.",
true,
ConfigKey.Scope.Account);
ConfigKey<Integer> RoutedIPv4NetworkMaxCidrSize = new ConfigKey<>(ConfigKey.CATEGORY_NETWORK, Integer.class,
"routed.ipv4.network.max.cidr.size", "30", "The maximum value of the cidr size for isolated networks in ROUTED mode",
true, ConfigKey.Scope.Account);

ConfigKey<Integer> RoutedNetworkMinCidrSize = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, Integer.class,
"routed.network.min.cidr.size",
"24",
"The minimum cidr size of routed network.",
true,
ConfigKey.Scope.Account);
ConfigKey<Integer> RoutedIPv4NetworkMinCidrSize = new ConfigKey<>(ConfigKey.CATEGORY_NETWORK, Integer.class,
"routed.ipv4.network.min.cidr.size", "24", "The minimum value of the cidr size for isolated networks in ROUTED mode",
true, ConfigKey.Scope.Account);

ConfigKey<Boolean> RoutedNetworkCidrAutoAllocationEnabled = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, Boolean.class,
"routed.network.cidr.auto.allocation.enabled",
ConfigKey<Boolean> RoutedIPv4NetworkCidrAutoAllocationEnabled = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, Boolean.class,
"routed.ipv4.network.cidr.auto.allocation.enabled",
"true",
"Indicates whether the auto-allocation of network CIDR for routed network is enabled or not.",
true,
Expand All @@ -87,7 +81,9 @@ public interface RoutedIpv4Manager extends PluggableService, Configurable {

boolean deleteIpv4SubnetForGuestNetwork(DeleteIpv4SubnetForGuestNetworkCmd deleteIpv4SubnetForGuestNetworkCmd);

boolean releaseIpv4SubnetForGuestNetwork(long networkId);
void releaseIpv4SubnetForGuestNetwork(long networkId);

void releaseIpv4SubnetForVpc(long vpcId);

List<? extends Ipv4GuestSubnetNetworkMap> listIpv4GuestSubnetsForGuestNetwork(ListIpv4SubnetsForGuestNetworkCmd listIpv4SubnetsForGuestNetworkCmd);

Expand All @@ -96,10 +92,14 @@ public interface RoutedIpv4Manager extends PluggableService, Configurable {
// Methods for internal calls
void getOrCreateIpv4SubnetForGuestNetwork(Network network, String networkCidr);

void getOrCreateIpv4SubnetForVpc(Vpc vpc, String networkCidr);

Ipv4GuestSubnetNetworkMap getOrCreateIpv4SubnetForGuestNetwork(Network network, Integer networkCidrSize);

void assignIpv4SubnetToNetwork(String cidr, long networkId);

void assignIpv4SubnetToVpc(String cidr, long vpcId);

// Methods for Routing firewall rules
FirewallRule createRoutingFirewallRule(CreateRoutingFirewallRuleCmd createRoutingFirewallRuleCmd) throws NetworkRuleConflictException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class Ipv4GuestSubnetNetworkMapVO implements Ipv4GuestSubnetNetworkMap {
@Column(name = "subnet")
private String subnet;

@Column(name = "vpc_id")
private Long vpcId;

@Column(name = "network_id")
private Long networkId;

Expand Down Expand Up @@ -97,6 +100,15 @@ public String getSubnet() {
return subnet;
}

@Override
public Long getVpcId() {
return vpcId;
}

public void setVpcId(Long vpcId) {
this.vpcId = vpcId;
}

@Override
public Long getNetworkId() {
return networkId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public interface Ipv4GuestSubnetNetworkMapDao extends GenericDao<Ipv4GuestSubnet
List<Ipv4GuestSubnetNetworkMapVO> listUsedByOtherAccounts(long parentId, Long accountId);
Ipv4GuestSubnetNetworkMapVO findFirstAvailable(long parentId, long cidrSize);
Ipv4GuestSubnetNetworkMapVO findByNetworkId(long networkId);
Ipv4GuestSubnetNetworkMapVO findByVpcId(long vpcId);
Ipv4GuestSubnetNetworkMapVO findBySubnet(String subnet);
List<Ipv4GuestSubnetNetworkMapVO> findSubnetsInStates(Ipv4GuestSubnetNetworkMap.State... states);
void deleteByParentId(long parentId);
List<Ipv4GuestSubnetNetworkMapVO> listAllNoParent();
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class Ipv4GuestSubnetNetworkMapDaoImpl extends GenericDaoBase<Ipv4GuestSu

protected SearchBuilder<Ipv4GuestSubnetNetworkMapVO> ParentStateSearch;
protected SearchBuilder<Ipv4GuestSubnetNetworkMapVO> ParentIdSearch;
protected SearchBuilder<Ipv4GuestSubnetNetworkMapVO> NoParentSearch;
protected SearchBuilder<Ipv4GuestSubnetNetworkMapVO> NetworkIdSearch;
protected SearchBuilder<Ipv4GuestSubnetNetworkMapVO> SubnetSearch;
protected SearchBuilder<Ipv4GuestSubnetNetworkMapVO> StatesSearch;
Expand All @@ -60,8 +61,12 @@ public void init() {
ParentIdSearch = createSearchBuilder();
ParentIdSearch.and("parentId", ParentIdSearch.entity().getParentId(), SearchCriteria.Op.EQ);
ParentIdSearch.done();
NoParentSearch = createSearchBuilder();
NoParentSearch.and("parentId", NoParentSearch.entity().getParentId(), SearchCriteria.Op.NULL);
NoParentSearch.done();
NetworkIdSearch = createSearchBuilder();
NetworkIdSearch.and("networkId", NetworkIdSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
NetworkIdSearch.and("vpcId", NetworkIdSearch.entity().getVpcId(), SearchCriteria.Op.EQ);
NetworkIdSearch.done();
SubnetSearch = createSearchBuilder();
SubnetSearch.and("subnet", SubnetSearch.entity().getSubnet(), SearchCriteria.Op.EQ);
Expand Down Expand Up @@ -129,6 +134,13 @@ public Ipv4GuestSubnetNetworkMapVO findByNetworkId(long networkId) {
return findOneBy(sc);
}

@Override
public Ipv4GuestSubnetNetworkMapVO findByVpcId(long vpcId) {
SearchCriteria<Ipv4GuestSubnetNetworkMapVO> sc = NetworkIdSearch.create();
sc.setParameters("vpcId", vpcId);
return findOneBy(sc);
}

@Override
public Ipv4GuestSubnetNetworkMapVO findBySubnet(String subnet) {
SearchCriteria<Ipv4GuestSubnetNetworkMapVO> sc = SubnetSearch.create();
Expand All @@ -149,4 +161,10 @@ public void deleteByParentId(long parentId) {
sc.setParameters("parentId", parentId);
remove(sc);
}

@Override
public List<Ipv4GuestSubnetNetworkMapVO> listAllNoParent() {
SearchCriteria<Ipv4GuestSubnetNetworkMapVO> sc = NoParentSearch.create();
return listBy(sc, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ CREATE TABLE `cloud`.`ip4_guest_subnet_network_map` (
`uuid` varchar(40) DEFAULT NULL,
`parent_id` bigint(20) unsigned COMMENT 'ip4 guest subnet which subnet belongs to',
`subnet` varchar(255) NOT NULL COMMENT 'subnet of the ip4 network',
`vpc_id` bigint(20) unsigned DEFAULT NULL COMMENT 'VPC which subnet is associated to',
`network_id` bigint(20) unsigned DEFAULT NULL COMMENT 'network which subnet is associated to',
`state` varchar(255) NOT NULL COMMENT 'state of the subnet',
`allocated` datetime default NULL,
Expand Down
19 changes: 10 additions & 9 deletions server/src/main/java/com/cloud/network/NetworkServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ private void checkSharedNetworkCidrOverlap(Long zoneId, long physicalNetworkId,
}
}

void validateNetworkCidrSize(Account caller, Integer cidrSize, String cidr, NetworkOffering networkOffering, long zoneId) {
void validateNetworkCidrSize(Account caller, Integer cidrSize, String cidr, NetworkOffering networkOffering, long accountId) {
if (!GuestType.Isolated.equals(networkOffering.getGuestType())) {
if (cidrSize != null) {
throw new InvalidParameterValueException("network cidr size is only applicable on Isolated networks");
Expand All @@ -1391,19 +1391,21 @@ void validateNetworkCidrSize(Account caller, Integer cidrSize, String cidr, Netw
if (NetworkOffering.RoutingMode.ROUTED.name().equals(networkOffering.getRoutingMode())
&& routedIpv4Manager.isVirtualRouterGateway(networkOffering)) {
if (cidr != null) {
if (!_accountMgr.isRootAdmin(caller.getId())) {
if (!networkOffering.isForVpc() && !_accountMgr.isRootAdmin(caller.getId())) {
throw new InvalidParameterValueException("Only root admin can set the gateway/netmask of Isolated networks with ROUTED mode");
}
return;
}
if (cidrSize == null) {
throw new InvalidParameterValueException("network cidr or cidr size is required for Isolated networks with ROUTED mode");
}
if (cidrSize > RoutedIPv4NetworkMaxCidrSize.valueIn(zoneId)) {
throw new InvalidParameterValueException("network cidr size cannot be bigger than maximum cidr size " + RoutedIPv4NetworkMaxCidrSize.value());
Integer maxCidrSize = routedIpv4Manager.RoutedIPv4NetworkMaxCidrSize.valueIn(accountId);
if (cidrSize > maxCidrSize) {
throw new InvalidParameterValueException("network cidr size cannot be bigger than maximum cidr size " + maxCidrSize);
}
if (cidrSize < RoutedIPv4NetworkMinCidrSize.valueIn(zoneId)) {
throw new InvalidParameterValueException("network cidr size cannot be bigger than minimum cidr size " + RoutedIPv4NetworkMinCidrSize.value());
Integer minCidrSize = routedIpv4Manager.RoutedIPv4NetworkMinCidrSize.valueIn(accountId);
if (cidrSize < minCidrSize) {
throw new InvalidParameterValueException("network cidr size cannot be smaller than minimum cidr size " + minCidrSize);
}
} else if (cidrSize != null) {
throw new InvalidParameterValueException("network cidr size is only applicable on Isolated networks with ROUTED mode: " + cidrSize);
Expand Down Expand Up @@ -1641,7 +1643,7 @@ public Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapac
}
}

validateNetworkCidrSize(caller, networkCidrSize, cidr, ntwkOff, zone.getId());
validateNetworkCidrSize(caller, networkCidrSize, cidr, ntwkOff, owner.getAccountId());

validateSharedNetworkRouterIPs(gateway, startIP, endIP, netmask, routerIPv4, routerIPv6, startIPv6, endIPv6, ip6Cidr, ntwkOff);

Expand Down Expand Up @@ -6139,8 +6141,7 @@ public String getConfigComponentName() {

@Override
public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey<?>[] {AllowDuplicateNetworkName, AllowEmptyStartEndIpAddress, VRPrivateInterfaceMtu, VRPublicInterfaceMtu, AllowUsersToSpecifyVRMtu,
RoutedIPv4NetworkMaxCidrSize, RoutedIPv4NetworkMinCidrSize};
return new ConfigKey<?>[] {AllowDuplicateNetworkName, AllowEmptyStartEndIpAddress, VRPrivateInterfaceMtu, VRPublicInterfaceMtu, AllowUsersToSpecifyVRMtu};
}

public boolean isDefaultAcl(Long aclId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,16 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
}
if (NetworkOffering.RoutingMode.ROUTED.name().equals(offering.getRoutingMode())) {
if (userSpecified.getCidr() != null) {
routedIpv4Manager.getOrCreateIpv4SubnetForGuestNetwork(config, userSpecified.getCidr());
if (config.getVpcId() == null) {
routedIpv4Manager.getOrCreateIpv4SubnetForGuestNetwork(config, userSpecified.getCidr());
}
} else {
if (userSpecified.getNetworkCidrSize() == null) {
throw new CloudRuntimeException("The network CIDR or CIDR size must be specified.");
}
if (config.getVpcId() != null) {
throw new CloudRuntimeException("The network CIDR must be specified for VPC networks.");
}
Ipv4GuestSubnetNetworkMap subnet = routedIpv4Manager.getOrCreateIpv4SubnetForGuestNetwork(config, userSpecified.getNetworkCidrSize());
if (subnet != null) {
final String[] cidrTuple = subnet.getSubnet().split("\\/");
Expand Down
14 changes: 14 additions & 0 deletions server/src/main/java/com/cloud/network/vpc/VpcManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
import org.apache.cloudstack.network.RoutedIpv4Manager;
import org.apache.cloudstack.query.QueryService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.EnumUtils;
Expand Down Expand Up @@ -268,6 +269,8 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
protected NetworkHelper networkHelper;
@Inject
private VpcPrivateGatewayTransactionCallable vpcTxCallable;
@Inject
RoutedIpv4Manager routedIpv4Manager;

private final ScheduledExecutorService _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("VpcChecker"));
private List<VpcProvider> vpcElements = null;
Expand Down Expand Up @@ -1231,6 +1234,11 @@ protected Vpc createVpc(final Boolean displayVpc, final VpcVO vpc) {
+ "and the hyphen ('-'); can't start or end with \"-\"");
}

// get or create Ipv4 subnet for ROUTED VPC
if (routedIpv4Manager.isRoutedVpc(vpc)) {
routedIpv4Manager.getOrCreateIpv4SubnetForVpc(vpc, cidr);
}

VpcVO vpcVO = Transaction.execute(new TransactionCallback<VpcVO>() {
@Override
public VpcVO doInTransaction(final TransactionStatus status) {
Expand All @@ -1244,6 +1252,10 @@ public VpcVO doInTransaction(final TransactionStatus status) {
if (vpcVO != null) {
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VPC_CREATE, vpcVO.getAccountId(), vpcVO.getZoneId(), vpcVO.getId(), vpcVO.getName(), Vpc.class.getName(), vpcVO.getUuid(), vpcVO.isDisplay());
}
// assign Ipv4 subnet to Routed VPC
if (routedIpv4Manager.isRoutedVpc(vpc)) {
routedIpv4Manager.assignIpv4SubnetToVpc(cidr, vpc.getId());
}
return vpcVO;
}

Expand Down Expand Up @@ -2102,6 +2114,8 @@ public boolean cleanupVpcResources(final long vpcId, final Account caller, final
_networkAclMgr.deleteNetworkACL(networkAcl);
}

routedIpv4Manager.releaseIpv4SubnetForVpc(vpcId);

VpcVO vpc = vpcDao.findById(vpcId);
annotationDao.removeByEntityType(AnnotationService.EntityType.VPC.name(), vpc.getUuid());
return success;
Expand Down
Loading