Skip to content

Commit

Permalink
Minor fix on floating IP and SNAT feature at kubevirt networking
Browse files Browse the repository at this point in the history
Change-Id: If45de2d83cf9c43105ad776767bb19c89636e5fa
  • Loading branch information
gunine committed Mar 20, 2021
1 parent f313604 commit 9793ec4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ private void setFloatingIpDownstreamRules(KubevirtRouter router,
install);
}


private void setFloatingIpDownstreamRulesToGatewayTunBridge(KubevirtRouter router,
KubevirtFloatingIp floatingIp,
KubevirtNetwork network,
Expand All @@ -316,14 +315,14 @@ private void setFloatingIpDownstreamRulesToGatewayTunBridge(KubevirtRouter route
log.warn("Failed to install floating Ip rules for floating ip {} " +
"because fail to fine the worker node that the associated port is running on",
floatingIp.floatingIp());
return;
}

PortNumber tunnelPortNumber = tunnelPort(electedGw, network);
if (tunnelPortNumber == null) {
return;
}


TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPDst(IpPrefix.valueOf(port.ipAddress(), 32))
Expand Down Expand Up @@ -357,15 +356,6 @@ private boolean isRelevantHelper() {
@Override
public void event(KubevirtRouterEvent event) {
switch (event.type()) {
case KUBEVIRT_ROUTER_CREATED:
eventExecutor.execute(() -> processRouterCreation(event.subject()));
break;
case KUBEVIRT_ROUTER_UPDATED:
eventExecutor.execute(() -> processRouterUpdate(event.subject()));
break;
case KUBEVIRT_ROUTER_REMOVED:
eventExecutor.execute(() -> processRouterDeletion(event.subject()));
break;
case KUBEVIRT_FLOATING_IP_ASSOCIATED:
eventExecutor.execute(() -> processFloatingIpAssociation(event.subject(),
event.floatingIp()));
Expand All @@ -381,42 +371,6 @@ public void event(KubevirtRouterEvent event) {
}
}

private void processRouterCreation(KubevirtRouter router) {
if (!isRelevantHelper()) {
return;
}
kubevirtRouterService.floatingIpsByRouter(router.name())
.stream()
.filter(fip -> fip.fixedIp() != null)
.forEach(fip -> {
processFloatingIpAssociation(router, fip);
});
}

private void processRouterDeletion(KubevirtRouter router) {
if (!isRelevantHelper()) {
return;
}
kubevirtRouterService.floatingIpsByRouter(router.name())
.stream()
.filter(fip -> fip.fixedIp() != null)
.forEach(fip -> {
processFloatingIpDisassociation(router, fip);
});
}

private void processRouterUpdate(KubevirtRouter router) {
if (!isRelevantHelper()) {
return;
}
kubevirtRouterService.floatingIpsByRouter(router.name())
.stream()
.filter(fip -> fip.fixedIp() != null)
.forEach(fip -> {
processFloatingIpAssociation(router, fip);
});
}

private void processFloatingIpAssociation(KubevirtRouter router, KubevirtFloatingIp floatingIp) {
if (!isRelevantHelper()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.onosproject.kubevirtnode.api.KubevirtApiConfigService;
import org.onosproject.kubevirtnode.api.KubevirtNode;
import org.onosproject.kubevirtnode.api.KubevirtNodeService;
import org.onosproject.kubevirtnode.api.KubevirtPhyInterface;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
Expand Down Expand Up @@ -470,14 +471,6 @@ public static KubevirtNode gatewayNodeForSpecifiedRouter(KubevirtNodeService nod
return (KubevirtNode) nodeService.completeNodes(GATEWAY).toArray()[router.hashCode() % numOfGateways];
}

/**
* Returns the mac address of the br-int port of specified device.
*
* @param deviceService device service
* @param deviceId device Id
* @return mac address of the br-int port
*/

/**
* Returns the mac address of the router.
*
Expand Down Expand Up @@ -553,13 +546,20 @@ public static KubevirtRouter getRouterForKubevirtNetwork(KubevirtRouterService r
* Returns the external patch port number with specified gateway.
*
* @param deviceService device service
* @param gatewayNode gateawy node
* @param gatewayNode gateway node
* @return external patch port number
*/
public static PortNumber externalPatchPortNum(DeviceService deviceService, KubevirtNode gatewayNode) {
KubevirtPhyInterface intf = gatewayNode.phyIntfs().stream().findFirst().orElse(null);
if (intf == null) {
log.warn("No external interface is attached to gateway {}", gatewayNode.hostname());
return null;
}

String patchPortName = "int-to-" + intf.network();
Port port = deviceService.getPorts(gatewayNode.intgBridge()).stream()
.filter(p -> p.isEnabled() &&
Objects.equals(p.annotations().value(PORT_NAME), "int-to-gateway"))
Objects.equals(p.annotations().value(PORT_NAME), patchPortName))
.findAny().orElse(null);

return port != null ? port.number() : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.onosproject.kubevirtnode.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
Expand Down Expand Up @@ -372,12 +371,8 @@ public static KubevirtNode buildKubevirtNode(Node node) {
nodeType = GATEWAY;
gatewayBridgeName = jsonNode.get(GATEWAY_BRIDGE_NAME).asText();
}
} catch (JSONException e) {
log.error("Failed to parse physnet config or gateway config object because of{}", e);
} catch (JsonMappingException e) {
log.error("Failed to parse physnet config or gateway config object because of{}", e);
} catch (JsonProcessingException e) {
log.error("Failed to parse physnet config or gateway config object because of{}", e);
} catch (JSONException | JsonProcessingException e) {
log.error("Failed to parse physnet config or gateway config object", e);
}

return DefaultKubevirtNode.builder()
Expand Down

0 comments on commit 9793ec4

Please sign in to comment.