From 9793ec4a9c18688b153fc0730410f0ab879087f9 Mon Sep 17 00:00:00 2001 From: Jian Li Date: Fri, 19 Mar 2021 15:03:32 +0900 Subject: [PATCH] Minor fix on floating IP and SNAT feature at kubevirt networking Change-Id: If45de2d83cf9c43105ad776767bb19c89636e5fa --- .../impl/KubevirtFloatingIpHandler.java | 48 +------------------ .../util/KubevirtNetworkingUtil.java | 20 ++++---- .../kubevirtnode/util/KubevirtNodeUtil.java | 9 +--- 3 files changed, 13 insertions(+), 64 deletions(-) diff --git a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtFloatingIpHandler.java b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtFloatingIpHandler.java index 726abf2c0a4..26e27ff6205 100644 --- a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtFloatingIpHandler.java +++ b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtFloatingIpHandler.java @@ -297,7 +297,6 @@ private void setFloatingIpDownstreamRules(KubevirtRouter router, install); } - private void setFloatingIpDownstreamRulesToGatewayTunBridge(KubevirtRouter router, KubevirtFloatingIp floatingIp, KubevirtNetwork network, @@ -316,6 +315,7 @@ 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); @@ -323,7 +323,6 @@ private void setFloatingIpDownstreamRulesToGatewayTunBridge(KubevirtRouter route return; } - TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder() .matchEthType(Ethernet.TYPE_IPV4) .matchIPDst(IpPrefix.valueOf(port.ipAddress(), 32)) @@ -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())); @@ -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; diff --git a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/util/KubevirtNetworkingUtil.java b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/util/KubevirtNetworkingUtil.java index e0614956c1e..94a7883d5de 100644 --- a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/util/KubevirtNetworkingUtil.java +++ b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/util/KubevirtNetworkingUtil.java @@ -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; @@ -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. * @@ -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; diff --git a/apps/kubevirt-node/app/src/main/java/org/onosproject/kubevirtnode/util/KubevirtNodeUtil.java b/apps/kubevirt-node/app/src/main/java/org/onosproject/kubevirtnode/util/KubevirtNodeUtil.java index f11547fc42d..a4b0abb1cbd 100644 --- a/apps/kubevirt-node/app/src/main/java/org/onosproject/kubevirtnode/util/KubevirtNodeUtil.java +++ b/apps/kubevirt-node/app/src/main/java/org/onosproject/kubevirtnode/util/KubevirtNodeUtil.java @@ -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; @@ -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()