Minor fix on floating IP and SNAT feature at kubevirt networking
Change-Id: If45de2d83cf9c43105ad776767bb19c89636e5fa
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 726abf2..26e27ff 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 @@
install);
}
-
private void setFloatingIpDownstreamRulesToGatewayTunBridge(KubevirtRouter router,
KubevirtFloatingIp floatingIp,
KubevirtNetwork network,
@@ -316,6 +315,7 @@
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 @@
return;
}
-
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPDst(IpPrefix.valueOf(port.ipAddress(), 32))
@@ -357,15 +356,6 @@
@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 @@
}
}
- 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 e061495..94a7883 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;
@@ -471,14 +472,6 @@
}
/**
- * 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.
*
* @param router kubevirt router
@@ -553,13 +546,20 @@
* 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 f11547f..a4b0abb 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 @@
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()