Skip to content

Commit

Permalink
Dynamic: connect to ALL (or ALL dedicated) BGP peers if no BGP peer m…
Browse files Browse the repository at this point in the history
…apping for the network/vpc
  • Loading branch information
weizhouapache committed Aug 22, 2024
1 parent 5439134 commit 4059b07
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,5 @@ public interface RoutedIpv4Manager extends PluggableService, Configurable {

Vpc changeBgpPeersForVpc(ChangeBgpPeersForVpcCmd changeBgpPeersForVpcCmd);

List<Long> getBgpPeersForAccount(Account owner, long zoneIdd);
List<Long> getBgpPeerIdsForAccount(Account owner, long zoneIdd);
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public class BgpPeerDaoImpl extends GenericDaoBase<BgpPeerVO, Long> implements B
protected SearchBuilder<BgpPeerVO> VpcIdSearch;
protected SearchBuilder<BgpPeerVO> AllFieldsSearch;

private static final String LIST_ALL_BGP_PEERS_IDS_FOR_ACCOUNT = "SELECT id FROM `cloud`.`bgp_peers` WHERE data_center_id = ? " +
private static final String LIST_ALL_BGP_PEERS_IDS_FOR_ACCOUNT = "SELECT id FROM `cloud`.`bgp_peers` WHERE removed IS NULL AND data_center_id = ? " +
"AND ((domain_id IS NULL AND account_id IS NULL) " +
"OR (domain_id = ? AND account_id IS NULL) " +
"OR (domain_id = ? AND account_id = ?))";

private static final String LIST_DEDICATED_BGP_PEERS_IDS_FOR_ACCOUNT = "SELECT id FROM `cloud`.`bgp_peers` WHERE data_center_id = ? " +
private static final String LIST_DEDICATED_BGP_PEERS_IDS_FOR_ACCOUNT = "SELECT id FROM `cloud`.`bgp_peers` WHERE removed IS NULL AND data_center_id = ? " +
"AND ((domain_id = ? AND account_id IS NULL) " +
"OR (domain_id = ? AND account_id = ?))";

Expand Down
8 changes: 8 additions & 0 deletions server/src/main/java/com/cloud/bgp/BGPServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class BGPServiceImpl implements BGPService {

Expand Down Expand Up @@ -392,6 +393,13 @@ public boolean applyBgpPeers(Network network, boolean continueOnError) throws Re
} else {
bgpPeers = bgpPeerDao.listNonRevokeByNetworkId(network.getId());
}
if (CollectionUtils.isEmpty(bgpPeers)) {
Account owner = accountDao.findByIdIncludingRemoved(network.getAccountId());
List<Long> bgpPeerIds = routedIpv4Manager.getBgpPeerIdsForAccount(owner, network.getDataCenterId());
bgpPeers = bgpPeerIds.stream()
.map(bgpPeerId -> bgpPeerDao.findById(bgpPeerId))
.collect(Collectors.toList());
}
LOGGER.debug(String.format("Applying BPG Peers for network [%s]: [%s]", network, bgpPeers));
return ((BgpServiceProvider) provider).applyBgpPeers(network, bgpPeers);
}
Expand Down
16 changes: 7 additions & 9 deletions server/src/main/java/com/cloud/network/NetworkServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1707,15 +1707,13 @@ public Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapac
}

// Validate BGP peers
if (vpcId != null && CollectionUtils.isNotEmpty(bgpPeerIds)) {
throw new InvalidParameterValueException("The BGP peers of VPC tiers will inherit from the VPC, do not add separately.");
}
if (CollectionUtils.isNotEmpty(bgpPeerIds) && !routedIpv4Manager.isDynamicRoutedNetwork(ntwkOff)) {
throw new InvalidParameterValueException("The network offering does not support Dynamic routing");
}
if (CollectionUtils.isEmpty(bgpPeerIds)) {
bgpPeerIds = routedIpv4Manager.getBgpPeersForAccount(owner, zone.getId());
} else {
if (CollectionUtils.isNotEmpty(bgpPeerIds)) {
if (vpcId != null) {
throw new InvalidParameterValueException("The BGP peers of VPC tiers will inherit from the VPC, do not add separately.");
}
if (!routedIpv4Manager.isDynamicRoutedNetwork(ntwkOff)) {
throw new InvalidParameterValueException("The network offering does not support Dynamic routing");
}
routedIpv4Manager.validateBgpPeers(owner, zone.getId(), bgpPeerIds);
}

Expand Down
10 changes: 4 additions & 6 deletions server/src/main/java/com/cloud/network/vpc/VpcManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1155,12 +1155,10 @@ public Vpc createVpc(final long zoneId, final long vpcOffId, final long vpcOwner
validateVpcCidrSize(caller, owner.getAccountId(), vpcOff, cidr, cidrSize);

// Validate BGP peers
if (CollectionUtils.isNotEmpty(bgpPeerIds) && !routedIpv4Manager.isDynamicRoutedVpc(vpcOff)) {
throw new InvalidParameterValueException("The VPC offering does not support Dynamic routing");
}
if (CollectionUtils.isEmpty(bgpPeerIds)) {
bgpPeerIds = routedIpv4Manager.getBgpPeersForAccount(owner, zone.getId());
} else {
if (CollectionUtils.isNotEmpty(bgpPeerIds)) {
if (!routedIpv4Manager.isDynamicRoutedVpc(vpcOff)) {
throw new InvalidParameterValueException("The VPC offering does not support Dynamic routing");
}
routedIpv4Manager.validateBgpPeers(owner, zone.getId(), bgpPeerIds);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,7 @@ public Vpc changeBgpPeersForVpc(ChangeBgpPeersForVpcCmd changeBgpPeersForVpcCmd)
}

@Override
public List<Long> getBgpPeersForAccount(Account owner, long zoneId) {
public List<Long> getBgpPeerIdsForAccount(Account owner, long zoneId) {
return bgpPeerDao.listAvailableBgpPeerIdsForAccount(zoneId, owner.getDomainId(), owner.getId(), UseSystemBgpPeers.valueIn(owner.getId()));
}

Expand Down

0 comments on commit 4059b07

Please sign in to comment.