mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-17 18:32:28 +02:00
[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
This commit is contained in:
parent
992be1d482
commit
176c83d3aa
@ -331,7 +331,7 @@ public class OpenstackIcmpHandler {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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()));
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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<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 @@ 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<String> 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<String> 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<String> 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));
|
||||
}
|
||||
}
|
||||
|
@ -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<ApplicationId> {
|
||||
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<ApplicationId> {
|
||||
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);
|
||||
|
@ -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<PortNumber> getGatewayExternalPorts(DeviceId deviceId);
|
||||
PortNumber getGatewayExternalPort(DeviceId deviceId);
|
||||
|
||||
/**
|
||||
* Returns group id for gateway load balance.
|
||||
|
@ -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<String> splitNameList(String interfaceName) {
|
||||
List<String> list = Lists.newArrayList();
|
||||
return Collections.addAll(list, interfaceName.split(",")) ? list : null;
|
||||
}
|
||||
}
|
||||
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
@ -155,23 +155,16 @@ public class ScalableGatewayManager implements ScalableGatewayService {
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user