Skip to content
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 @@ -396,6 +396,12 @@ boolean isVpcEnabledForDistributedRouter(long vpcId) {
return vpc.usesDistributedRouter();
}

boolean isOvsDistributedRouterVpc(long vpcId) {
VpcVO vpc = _vpcDao.findById(vpcId);
return vpc != null && vpc.usesDistributedRouter()
&& _vpcMgr.isProviderSupportServiceInVpc(vpcId, Network.Service.Connectivity, Network.Provider.Ovs);
}

@Override
public void checkAndPrepareHostForTunnelNetwork(Network nw, Host host) {
if (nw.getVpcId() != null && isVpcEnabledForDistributedRouter(nw.getVpcId())) {
Expand Down Expand Up @@ -684,25 +690,28 @@ private void handleVmStateChange(VMInstanceVO vm) {
}

for (Long vpcId: vpcIds) {
VpcVO vpc = _vpcDao.findById(vpcId);
// nothing to do if the VPC is not setup for distributed routing
if (vpc == null || !vpc.usesDistributedRouter()) {
return;
if (!isOvsDistributedRouterVpc(vpcId)) {
continue;
}

// get the list of hosts on which VPC spans (i.e hosts that need to be aware of VPC topology change update)
List<Long> vpcSpannedHostIds = _ovsNetworkToplogyGuru.getVpcSpannedHosts(vpcId);
String bridgeName=generateBridgeNameForVpc(vpcId);

OvsVpcPhysicalTopologyConfigCommand topologyConfigCommand = prepareVpcTopologyUpdate(vpcId);
topologyConfigCommand.setSequenceNumber(getNextTopologyUpdateSequenceNumber(vpcId));

// send topology change update to VPC spanned hosts
for (Long id: vpcSpannedHostIds) {
if (!sendVpcTopologyChangeUpdate(topologyConfigCommand, id, bridgeName)) {
logger.debug("Failed to send VPC topology change update to host : " + id + ". Moving on " +
"with rest of the host update.");
try {
// get the list of hosts on which VPC spans (i.e hosts that need to be aware of VPC topology change update)
List<Long> vpcSpannedHostIds = _ovsNetworkToplogyGuru.getVpcSpannedHosts(vpcId);
String bridgeName=generateBridgeNameForVpc(vpcId);

OvsVpcPhysicalTopologyConfigCommand topologyConfigCommand = prepareVpcTopologyUpdate(vpcId);
topologyConfigCommand.setSequenceNumber(getNextTopologyUpdateSequenceNumber(vpcId));

// send topology change update to VPC spanned hosts
for (Long id: vpcSpannedHostIds) {
if (!sendVpcTopologyChangeUpdate(topologyConfigCommand, id, bridgeName)) {
logger.debug("Failed to send VPC topology change update to host : " + id + ". Moving on " +
"with rest of the host update.");
}
}
} catch (RuntimeException e) {
logger.error("Failed to update OVS distributed-router topology for VPC {} after VM {} changed state",
vpcId, vm.getId(), e);
}
}
}
Expand Down Expand Up @@ -754,20 +763,32 @@ OvsVpcPhysicalTopologyConfigCommand prepareVpcTopologyUpdate(long vpcId) {
}

for (Network network: vpcNetworks) {
if (network.getBroadcastDomainType() != BroadcastDomainType.Vswitch || network.getBroadcastUri() == null) {
throw new CloudRuntimeException(String.format(
"OVS distributed-router VPC %s contains network %s without a Vswitch broadcast URI",
vpc.getUuid(), network.getUuid()));
}
String key = network.getBroadcastUri().getAuthority();
long gre_key;
if (key.contains(".")) {
String[] parts = key.split("\\.");
gre_key = Long.parseLong(parts[1]);
} else {
try {
gre_key = Long.parseLong(BroadcastDomainType.getValue(key));
} catch (Exception e) {
return null;
}
String expectedPrefix = vpcId + ".";
if (key == null || !key.startsWith(expectedPrefix) || key.indexOf('.', expectedPrefix.length()) >= 0) {
throw new CloudRuntimeException(String.format(
"OVS distributed-router network %s has invalid broadcast key %s for VPC %s",
network.getUuid(), key, vpc.getUuid()));
}
int greKey;
try {
greKey = Integer.parseInt(key.substring(expectedPrefix.length()));
} catch (NumberFormatException e) {
throw new CloudRuntimeException(String.format(
"OVS distributed-router network %s has non-numeric GRE key %s",
network.getUuid(), key.substring(expectedPrefix.length())), e);
}
NicVO nic = _nicDao.findByIp4AddressAndNetworkId(network.getGateway(), network.getId());
OvsVpcPhysicalTopologyConfigCommand.Tier tier = new OvsVpcPhysicalTopologyConfigCommand.Tier(gre_key,
if (nic == null) {
throw new CloudRuntimeException(String.format(
"Unable to find the gateway NIC for OVS distributed-router network %s", network.getUuid()));
}
OvsVpcPhysicalTopologyConfigCommand.Tier tier = new OvsVpcPhysicalTopologyConfigCommand.Tier(greKey,
network.getUuid(), network.getGateway(), nic.getMacAddress(), network.getCidr());
tiers.add(tier);
}
Expand Down Expand Up @@ -802,9 +823,9 @@ public class NetworkAclEventsSubscriber implements MessageSubscriber {
public void onPublishMessage(String senderAddress, String subject, Object args) {
try {
NetworkVO network = (NetworkVO) args;
String bridgeName=generateBridgeNameForVpc(network.getVpcId());
if (network.getVpcId() != null && isVpcEnabledForDistributedRouter(network.getVpcId())) {
long vpcId = network.getVpcId();
Long vpcId = network.getVpcId();
if (vpcId != null && isOvsDistributedRouterVpc(vpcId)) {
String bridgeName = generateBridgeNameForVpc(vpcId);
OvsVpcRoutingPolicyConfigCommand cmd = prepareVpcRoutingPolicyUpdate(vpcId);
cmd.setSequenceNumber(getNextRoutingPolicyUpdateSequenceNumber(vpcId));

Expand Down
Loading
Loading