From 176c83d3aa0f4ea32d3adfa8ff1cb6767685e176 Mon Sep 17 00:00:00 2001 From: Kyuhwi Choi Date: Thu, 14 Jul 2016 11:39:37 +0900 Subject: [PATCH] [ONOS-4871] Fix gateway external port from list to single port - Fix GatewayNode externalInterface from list to string - Fix GatewayService externalPort from list to portNumber Change-Id: I8869c7bf550e005db854b464763cc2bc321faa6a --- .../routing/OpenstackIcmpHandler.java | 2 +- .../routing/OpenstackPnatHandler.java | 4 +-- .../routing/OpenstackRoutingManager.java | 2 +- .../OpenstackRoutingRulePopulator.java | 4 +-- .../scalablegateway/api/GatewayNode.java | 29 +++++++++---------- .../api/GatewayNodeConfig.java | 11 +------ .../api/ScalableGatewayService.java | 6 ++-- .../cli/ScalableGatewayAddCommand.java | 10 +------ .../cli/ScalableGatewayListCommand.java | 2 +- .../impl/ScalableGatewayManager.java | 17 ++++------- 10 files changed, 30 insertions(+), 57 deletions(-) diff --git a/apps/openstacknetworking/routing/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackIcmpHandler.java b/apps/openstacknetworking/routing/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackIcmpHandler.java index d9e632b858..6eaddf1cc2 100644 --- a/apps/openstacknetworking/routing/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackIcmpHandler.java +++ b/apps/openstacknetworking/routing/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackIcmpHandler.java @@ -331,7 +331,7 @@ public class OpenstackIcmpHandler { private Map getExternalInfo() { Map externalInfoMap = Maps.newHashMap(); gatewayService.getGatewayDeviceIds().forEach(deviceId -> - externalInfoMap.putIfAbsent(deviceId, gatewayService.getGatewayExternalPorts(deviceId).get(0))); + externalInfoMap.putIfAbsent(deviceId, gatewayService.getGatewayExternalPort(deviceId))); return externalInfoMap; } } diff --git a/apps/openstacknetworking/routing/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackPnatHandler.java b/apps/openstacknetworking/routing/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackPnatHandler.java index ce33e9eb4e..137c090034 100644 --- a/apps/openstacknetworking/routing/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackPnatHandler.java +++ b/apps/openstacknetworking/routing/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackPnatHandler.java @@ -147,11 +147,11 @@ public class OpenstackPnatHandler implements Runnable { ScalableGatewayService gatewayService = getService(ScalableGatewayService.class); GatewayNode gatewayNode = gatewayService.getGatewayNode(deviceId); - if (gatewayNode.getGatewayExternalInterfaceNames().size() == 0) { + if (gatewayNode.getGatewayExternalInterfaceName() == null) { log.error(EXTERNAL_PORT_NULL, deviceId.toString()); return; } - treatment.setOutput(gatewayService.getGatewayExternalPorts(deviceId).get(0)); + treatment.setOutput(gatewayService.getGatewayExternalPort(deviceId)); ethernet.resetChecksum(); diff --git a/apps/openstacknetworking/routing/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackRoutingManager.java b/apps/openstacknetworking/routing/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackRoutingManager.java index cbc8f18f12..bfcb2b8c2b 100644 --- a/apps/openstacknetworking/routing/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackRoutingManager.java +++ b/apps/openstacknetworking/routing/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackRoutingManager.java @@ -468,7 +468,7 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { DeviceId deviceId = pkt.receivedFrom().deviceId(); Port port = null; port = deviceService.getPort(deviceId, - gatewayService.getGatewayExternalPorts(deviceId).get(0)); + gatewayService.getGatewayExternalPort(deviceId)); if (port != null) { OpenstackPort openstackPort = getOpenstackPort(ethernet.getSourceMAC(), Ip4Address.valueOf(iPacket.getSourceAddress())); diff --git a/apps/openstacknetworking/routing/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackRoutingRulePopulator.java b/apps/openstacknetworking/routing/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackRoutingRulePopulator.java index 95e15c35b7..d2c928fe2d 100644 --- a/apps/openstacknetworking/routing/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackRoutingRulePopulator.java +++ b/apps/openstacknetworking/routing/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackRoutingRulePopulator.java @@ -188,7 +188,7 @@ public class OpenstackRoutingRulePopulator { tBuilder.setIpSrc(externalIp); gatewayService.getGatewayNodes().forEach(node -> { - tBuilder.setOutput(gatewayService.getGatewayExternalPorts(node.getGatewayDeviceId()).get(0)); + tBuilder.setOutput(gatewayService.getGatewayExternalPort(node.getGatewayDeviceId())); ForwardingObjective fo = DefaultForwardingObjective.builder() .withSelector(sBuilder.build()) .withTreatment(tBuilder.build()) @@ -548,7 +548,7 @@ public class OpenstackRoutingRulePopulator { } private PortNumber getExternalPortNum(DeviceId deviceId) { - return checkNotNull(gatewayService.getGatewayExternalPorts(deviceId).get(0), PORTNOTNULL); + return checkNotNull(gatewayService.getGatewayExternalPort(deviceId), PORTNOTNULL); } /** diff --git a/apps/scalablegateway/src/main/java/org/onosproject/scalablegateway/api/GatewayNode.java b/apps/scalablegateway/src/main/java/org/onosproject/scalablegateway/api/GatewayNode.java index 3b9af7c26a..c02c1ec8ce 100644 --- a/apps/scalablegateway/src/main/java/org/onosproject/scalablegateway/api/GatewayNode.java +++ b/apps/scalablegateway/src/main/java/org/onosproject/scalablegateway/api/GatewayNode.java @@ -15,12 +15,9 @@ */ package org.onosproject.scalablegateway.api; -import com.google.common.collect.ImmutableList; import org.onlab.packet.Ip4Address; import org.onosproject.net.DeviceId; -import java.util.List; - import static com.google.common.base.Preconditions.checkNotNull; /** @@ -28,13 +25,13 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public final class GatewayNode { private final DeviceId gatewayDeviceId; - private final List gatewayExternalInterfaceNames; + private final String gatewayExternalInterfaceName; private final Ip4Address dataIpAddress; - private GatewayNode(DeviceId gatewayDeviceId, List gatewayExternalInterfaceNames, + private GatewayNode(DeviceId gatewayDeviceId, String gatewayExternalInterfaceName, Ip4Address dataIpAddress) { this.gatewayDeviceId = gatewayDeviceId; - this.gatewayExternalInterfaceNames = gatewayExternalInterfaceNames; + this.gatewayExternalInterfaceName = gatewayExternalInterfaceName; this.dataIpAddress = dataIpAddress; } @@ -48,12 +45,12 @@ public final class GatewayNode { } /** - * Returns the list of gateway`s interface names. + * Returns the gateway`s interface name. * - * @return The list of interface names + * @return The gateway`s interface name */ - public List getGatewayExternalInterfaceNames() { - return ImmutableList.copyOf(gatewayExternalInterfaceNames); + public String getGatewayExternalInterfaceName() { + return gatewayExternalInterfaceName; } /** @@ -80,7 +77,7 @@ public final class GatewayNode { public static final class Builder { private DeviceId gatewayDeviceId; - private List gatewayExternalInterfaceNames; + private String gatewayExternalInterfaceName; private Ip4Address dataIpAddress; /** @@ -95,13 +92,13 @@ public final class GatewayNode { } /** - * Sets the list of gateway`s interface names. + * Sets the gateway`s interface name. * - * @param names The list of gateway`s interface name + * @param name The gateway`s interface name * @return Builder object */ - public Builder gatewayExternalInterfaceNames(List names) { - this.gatewayExternalInterfaceNames = names; + public Builder gatewayExternalInterfaceName(String name) { + this.gatewayExternalInterfaceName = name; return this; } @@ -122,7 +119,7 @@ public final class GatewayNode { * @return GatewayNode object */ public GatewayNode build() { - return new GatewayNode(checkNotNull(gatewayDeviceId), checkNotNull(gatewayExternalInterfaceNames), + return new GatewayNode(checkNotNull(gatewayDeviceId), checkNotNull(gatewayExternalInterfaceName), checkNotNull(dataIpAddress)); } } diff --git a/apps/scalablegateway/src/main/java/org/onosproject/scalablegateway/api/GatewayNodeConfig.java b/apps/scalablegateway/src/main/java/org/onosproject/scalablegateway/api/GatewayNodeConfig.java index 4ab87b45a4..0d4f561291 100644 --- a/apps/scalablegateway/src/main/java/org/onosproject/scalablegateway/api/GatewayNodeConfig.java +++ b/apps/scalablegateway/src/main/java/org/onosproject/scalablegateway/api/GatewayNodeConfig.java @@ -18,7 +18,6 @@ package org.onosproject.scalablegateway.api; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ObjectNode; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import org.onlab.packet.Ip4Address; import org.onosproject.core.ApplicationId; @@ -26,8 +25,6 @@ import org.onosproject.net.DeviceId; import org.onosproject.net.config.Config; import org.slf4j.Logger; -import java.util.Collections; -import java.util.List; import java.util.Set; import java.util.stream.StreamSupport; @@ -64,8 +61,7 @@ public class GatewayNodeConfig extends Config { try { nodes.add(new GatewayNode.Builder() .gatewayDeviceId(DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText())) - .gatewayExternalInterfaceNames( - getExternalInterfaceName(jsonNode.path(EXTERNAL_INTERFACE_NAME).asText())) + .gatewayExternalInterfaceName(jsonNode.path(EXTERNAL_INTERFACE_NAME).asText()) .dataIpAddress(Ip4Address.valueOf(jsonNode.path(DATAPLANE_IP).asText())).build()); } catch (IllegalArgumentException | NullPointerException e) { log.error("Failed to read {}", e.toString()); @@ -74,11 +70,6 @@ public class GatewayNodeConfig extends Config { return nodes; } - private List getExternalInterfaceName(String s) { - List list = Lists.newArrayList(); - return Collections.addAll(list, s.split(",")) ? list : null; - } - @Override public boolean isValid() { JsonNode jsonNodes = object.get(NODES); diff --git a/apps/scalablegateway/src/main/java/org/onosproject/scalablegateway/api/ScalableGatewayService.java b/apps/scalablegateway/src/main/java/org/onosproject/scalablegateway/api/ScalableGatewayService.java index bd1b29e84f..d3d0f862ad 100644 --- a/apps/scalablegateway/src/main/java/org/onosproject/scalablegateway/api/ScalableGatewayService.java +++ b/apps/scalablegateway/src/main/java/org/onosproject/scalablegateway/api/ScalableGatewayService.java @@ -35,12 +35,12 @@ public interface ScalableGatewayService { GatewayNode getGatewayNode(DeviceId deviceId); /** - * Returns the list of gateway`s port numbers with the given device identifier. + * Returns the gateway`s port number with the given device identifier. * * @param deviceId The gateway node deviceId - * @return The list of external interface port number + * @return The external interface port number */ - List getGatewayExternalPorts(DeviceId deviceId); + PortNumber getGatewayExternalPort(DeviceId deviceId); /** * Returns group id for gateway load balance. diff --git a/apps/scalablegateway/src/main/java/org/onosproject/scalablegateway/cli/ScalableGatewayAddCommand.java b/apps/scalablegateway/src/main/java/org/onosproject/scalablegateway/cli/ScalableGatewayAddCommand.java index 911062c945..4a93563a0b 100644 --- a/apps/scalablegateway/src/main/java/org/onosproject/scalablegateway/cli/ScalableGatewayAddCommand.java +++ b/apps/scalablegateway/src/main/java/org/onosproject/scalablegateway/cli/ScalableGatewayAddCommand.java @@ -16,7 +16,6 @@ package org.onosproject.scalablegateway.cli; -import com.google.common.collect.Lists; import org.apache.karaf.shell.commands.Argument; import org.apache.karaf.shell.commands.Command; import org.onlab.packet.Ip4Address; @@ -25,9 +24,6 @@ import org.onosproject.net.DeviceId; import org.onosproject.scalablegateway.api.GatewayNode; import org.onosproject.scalablegateway.api.ScalableGatewayService; -import java.util.Collections; -import java.util.List; - /** * Adds gateway node information for scalablegateway node managements. */ @@ -60,7 +56,7 @@ public class ScalableGatewayAddCommand extends AbstractShellCommand { GatewayNode gatewayNode = GatewayNode.builder() .gatewayDeviceId(DeviceId.deviceId(deviceId)) .dataIpAddress(Ip4Address.valueOf(ipAddress)) - .gatewayExternalInterfaceNames(splitNameList(interfaceName)) + .gatewayExternalInterfaceName(interfaceName) .build(); if (service.addGatewayNode(gatewayNode)) { print(SUCCESS); @@ -69,8 +65,4 @@ public class ScalableGatewayAddCommand extends AbstractShellCommand { } } - private List splitNameList(String interfaceName) { - List list = Lists.newArrayList(); - return Collections.addAll(list, interfaceName.split(",")) ? list : null; - } } diff --git a/apps/scalablegateway/src/main/java/org/onosproject/scalablegateway/cli/ScalableGatewayListCommand.java b/apps/scalablegateway/src/main/java/org/onosproject/scalablegateway/cli/ScalableGatewayListCommand.java index d48dd4360e..87db21e05f 100644 --- a/apps/scalablegateway/src/main/java/org/onosproject/scalablegateway/cli/ScalableGatewayListCommand.java +++ b/apps/scalablegateway/src/main/java/org/onosproject/scalablegateway/cli/ScalableGatewayListCommand.java @@ -35,6 +35,6 @@ public class ScalableGatewayListCommand extends AbstractShellCommand { service.getGatewayNodes().forEach(node -> print(FORMAT, node.getGatewayDeviceId().toString(), node.getDataIpAddress().toString(), - node.getGatewayExternalInterfaceNames().toString())); + node.getGatewayExternalInterfaceName().toString())); } } diff --git a/apps/scalablegateway/src/main/java/org/onosproject/scalablegateway/impl/ScalableGatewayManager.java b/apps/scalablegateway/src/main/java/org/onosproject/scalablegateway/impl/ScalableGatewayManager.java index 383684e42f..adf354ebbd 100644 --- a/apps/scalablegateway/src/main/java/org/onosproject/scalablegateway/impl/ScalableGatewayManager.java +++ b/apps/scalablegateway/src/main/java/org/onosproject/scalablegateway/impl/ScalableGatewayManager.java @@ -155,23 +155,16 @@ public class ScalableGatewayManager implements ScalableGatewayService { } @Override - public List getGatewayExternalPorts(DeviceId deviceId) { + public PortNumber getGatewayExternalPort(DeviceId deviceId) { GatewayNode gatewayNode = checkNotNull(gatewayNodeMap.get(deviceId).value(), GATEWAYNODE_CAN_NOT_BE_NULL); - List portNumbers = Lists.newArrayList(); - gatewayNode.getGatewayExternalInterfaceNames() + String externalInterfaceName = gatewayNode.getGatewayExternalInterfaceName(); + Optional port = deviceService.getPorts(deviceId) .stream() - .forEach(name -> portNumbers.add(findPortNumFromPortName(gatewayNode.getGatewayDeviceId(), name))); - return portNumbers; - } - - private PortNumber findPortNumFromPortName(DeviceId gatewayDeviceId, String name) { - Optional port = deviceService.getPorts(gatewayDeviceId) - .stream() - .filter(p -> p.annotations().value(PORT_NAME).equals(name)) + .filter(p -> p.annotations().value(PORT_NAME).equals(externalInterfaceName)) .findFirst(); if (!port.isPresent()) { - log.error("Cannot find port {} in gateway device {}", name, gatewayDeviceId); + log.error("Cannot find port {} in gateway device {}", externalInterfaceName, deviceId); return null; }