Skip to content

Commit

Permalink
Reserve the vRouter IP from IP pool at network creation phase
Browse files Browse the repository at this point in the history
Change-Id: I5ccbd83088f521f9386046efefa0d4f92a195c4c
(cherry picked from commit a98e311)
  • Loading branch information
gunine committed Apr 8, 2021
1 parent c3d410a commit fc7e6cf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ public class KubevirtListIpAddressCommand extends AbstractShellCommand {
@Override
protected void doExecute() throws Exception {
KubevirtNetworkService service = get(KubevirtNetworkService.class);

if (networkId == null) {
error("No network identifier was specified");
return;
}

KubevirtNetwork network = service.network(networkId);

if (network == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.onosproject.core.CoreService;
import org.onosproject.kubevirtnetworking.api.KubevirtFlowRuleService;
import org.onosproject.kubevirtnetworking.api.KubevirtNetwork;
import org.onosproject.kubevirtnetworking.api.KubevirtNetworkAdminService;
import org.onosproject.kubevirtnetworking.api.KubevirtNetworkEvent;
import org.onosproject.kubevirtnetworking.api.KubevirtNetworkListener;
import org.onosproject.kubevirtnetworking.api.KubevirtNetworkService;
Expand Down Expand Up @@ -156,7 +157,7 @@ public class KubevirtNetworkHandler {
protected KubevirtNodeService nodeService;

@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected KubevirtNetworkService networkService;
protected KubevirtNetworkAdminService networkService;

@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected KubevirtFlowRuleService flowService;
Expand Down Expand Up @@ -834,6 +835,13 @@ private void setGatewayIcmpRuleForProviderInternalNetwork(KubevirtRouter router,
install);
}

private void reserveVrouterIp(KubevirtNetwork network) {
String networkId = network.networkId();
IpAddress vrouterIp = network.ipPool().start();

networkService.reserveIp(networkId, vrouterIp);
}

private class InternalRouterEventListener implements KubevirtRouterListener {
private boolean isRelevantHelper() {
return Objects.equals(localNodeId, leadershipService.getLeader(appId.name()));
Expand Down Expand Up @@ -1097,6 +1105,8 @@ private void processNetworkCreation(KubevirtNetwork network) {
initIntegrationTunnelBridge(network);
break;
case FLAT:
reserveVrouterIp(network);
break;
case VLAN:
break;
default:
Expand Down Expand Up @@ -1194,6 +1204,8 @@ private void processNodeCompletion(KubevirtNode node) {
setDefaultGatewayRuleToWorkerNodeWhenNodeCreated(node, network);
break;
case FLAT:
reserveVrouterIp(network);
break;
case VLAN:
default:
// do nothing
Expand Down

0 comments on commit fc7e6cf

Please sign in to comment.