[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
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 d9e632b..6eaddf1 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 @@
private Map<DeviceId, PortNumber> getExternalInfo() {
Map<DeviceId, PortNumber> 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 ce33e9e..137c090 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 @@
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 cbc8f18..bfcb2b8 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 @@
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 95e15c3..d2c928f 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 @@
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 @@
}
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 3b9af7c..c02c1ec 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 @@
*/
public final class GatewayNode {
private final DeviceId gatewayDeviceId;
- private final List<String> gatewayExternalInterfaceNames;
+ private final String gatewayExternalInterfaceName;
private final Ip4Address dataIpAddress;
- private GatewayNode(DeviceId gatewayDeviceId, List<String> 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 @@
}
/**
- * 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<String> getGatewayExternalInterfaceNames() {
- return ImmutableList.copyOf(gatewayExternalInterfaceNames);
+ public String getGatewayExternalInterfaceName() {
+ return gatewayExternalInterfaceName;
}
/**
@@ -80,7 +77,7 @@
public static final class Builder {
private DeviceId gatewayDeviceId;
- private List<String> gatewayExternalInterfaceNames;
+ private String gatewayExternalInterfaceName;
private Ip4Address dataIpAddress;
/**
@@ -95,13 +92,13 @@
}
/**
- * 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<String> names) {
- this.gatewayExternalInterfaceNames = names;
+ public Builder gatewayExternalInterfaceName(String name) {
+ this.gatewayExternalInterfaceName = name;
return this;
}
@@ -122,7 +119,7 @@
* @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 4ab87b4..0d4f561 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 @@
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.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 @@
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 @@
return nodes;
}
- private List<String> getExternalInterfaceName(String s) {
- List<String> 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 bd1b29e..d3d0f86 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 @@
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<PortNumber> 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 911062c..4a93563 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.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 @@
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 @@
}
}
- private List<String> splitNameList(String interfaceName) {
- List<String> 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 d48dd43..87db21e 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 @@
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 383684e..adf354e 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 @@
}
@Override
- public List<PortNumber> getGatewayExternalPorts(DeviceId deviceId) {
+ public PortNumber getGatewayExternalPort(DeviceId deviceId) {
GatewayNode gatewayNode = checkNotNull(gatewayNodeMap.get(deviceId).value(), GATEWAYNODE_CAN_NOT_BE_NULL);
- List<PortNumber> portNumbers = Lists.newArrayList();
- gatewayNode.getGatewayExternalInterfaceNames()
+ String externalInterfaceName = gatewayNode.getGatewayExternalInterfaceName();
+ Optional<Port> port = deviceService.getPorts(deviceId)
.stream()
- .forEach(name -> portNumbers.add(findPortNumFromPortName(gatewayNode.getGatewayDeviceId(), name)));
- return portNumbers;
- }
-
- private PortNumber findPortNumFromPortName(DeviceId gatewayDeviceId, String name) {
- Optional<Port> 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;
}