Committed by
Gerrit Code Review
[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
Showing
10 changed files
with
30 additions
and
57 deletions
... | @@ -331,7 +331,7 @@ public class OpenstackIcmpHandler { | ... | @@ -331,7 +331,7 @@ public class OpenstackIcmpHandler { |
331 | private Map<DeviceId, PortNumber> getExternalInfo() { | 331 | private Map<DeviceId, PortNumber> getExternalInfo() { |
332 | Map<DeviceId, PortNumber> externalInfoMap = Maps.newHashMap(); | 332 | Map<DeviceId, PortNumber> externalInfoMap = Maps.newHashMap(); |
333 | gatewayService.getGatewayDeviceIds().forEach(deviceId -> | 333 | gatewayService.getGatewayDeviceIds().forEach(deviceId -> |
334 | - externalInfoMap.putIfAbsent(deviceId, gatewayService.getGatewayExternalPorts(deviceId).get(0))); | 334 | + externalInfoMap.putIfAbsent(deviceId, gatewayService.getGatewayExternalPort(deviceId))); |
335 | return externalInfoMap; | 335 | return externalInfoMap; |
336 | } | 336 | } |
337 | } | 337 | } | ... | ... |
... | @@ -147,11 +147,11 @@ public class OpenstackPnatHandler implements Runnable { | ... | @@ -147,11 +147,11 @@ public class OpenstackPnatHandler implements Runnable { |
147 | 147 | ||
148 | ScalableGatewayService gatewayService = getService(ScalableGatewayService.class); | 148 | ScalableGatewayService gatewayService = getService(ScalableGatewayService.class); |
149 | GatewayNode gatewayNode = gatewayService.getGatewayNode(deviceId); | 149 | GatewayNode gatewayNode = gatewayService.getGatewayNode(deviceId); |
150 | - if (gatewayNode.getGatewayExternalInterfaceNames().size() == 0) { | 150 | + if (gatewayNode.getGatewayExternalInterfaceName() == null) { |
151 | log.error(EXTERNAL_PORT_NULL, deviceId.toString()); | 151 | log.error(EXTERNAL_PORT_NULL, deviceId.toString()); |
152 | return; | 152 | return; |
153 | } | 153 | } |
154 | - treatment.setOutput(gatewayService.getGatewayExternalPorts(deviceId).get(0)); | 154 | + treatment.setOutput(gatewayService.getGatewayExternalPort(deviceId)); |
155 | 155 | ||
156 | ethernet.resetChecksum(); | 156 | ethernet.resetChecksum(); |
157 | 157 | ... | ... |
... | @@ -468,7 +468,7 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -468,7 +468,7 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
468 | DeviceId deviceId = pkt.receivedFrom().deviceId(); | 468 | DeviceId deviceId = pkt.receivedFrom().deviceId(); |
469 | Port port = null; | 469 | Port port = null; |
470 | port = deviceService.getPort(deviceId, | 470 | port = deviceService.getPort(deviceId, |
471 | - gatewayService.getGatewayExternalPorts(deviceId).get(0)); | 471 | + gatewayService.getGatewayExternalPort(deviceId)); |
472 | if (port != null) { | 472 | if (port != null) { |
473 | OpenstackPort openstackPort = getOpenstackPort(ethernet.getSourceMAC(), | 473 | OpenstackPort openstackPort = getOpenstackPort(ethernet.getSourceMAC(), |
474 | Ip4Address.valueOf(iPacket.getSourceAddress())); | 474 | Ip4Address.valueOf(iPacket.getSourceAddress())); | ... | ... |
... | @@ -188,7 +188,7 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -188,7 +188,7 @@ public class OpenstackRoutingRulePopulator { |
188 | 188 | ||
189 | tBuilder.setIpSrc(externalIp); | 189 | tBuilder.setIpSrc(externalIp); |
190 | gatewayService.getGatewayNodes().forEach(node -> { | 190 | gatewayService.getGatewayNodes().forEach(node -> { |
191 | - tBuilder.setOutput(gatewayService.getGatewayExternalPorts(node.getGatewayDeviceId()).get(0)); | 191 | + tBuilder.setOutput(gatewayService.getGatewayExternalPort(node.getGatewayDeviceId())); |
192 | ForwardingObjective fo = DefaultForwardingObjective.builder() | 192 | ForwardingObjective fo = DefaultForwardingObjective.builder() |
193 | .withSelector(sBuilder.build()) | 193 | .withSelector(sBuilder.build()) |
194 | .withTreatment(tBuilder.build()) | 194 | .withTreatment(tBuilder.build()) |
... | @@ -548,7 +548,7 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -548,7 +548,7 @@ public class OpenstackRoutingRulePopulator { |
548 | } | 548 | } |
549 | 549 | ||
550 | private PortNumber getExternalPortNum(DeviceId deviceId) { | 550 | private PortNumber getExternalPortNum(DeviceId deviceId) { |
551 | - return checkNotNull(gatewayService.getGatewayExternalPorts(deviceId).get(0), PORTNOTNULL); | 551 | + return checkNotNull(gatewayService.getGatewayExternalPort(deviceId), PORTNOTNULL); |
552 | } | 552 | } |
553 | 553 | ||
554 | /** | 554 | /** | ... | ... |
... | @@ -15,12 +15,9 @@ | ... | @@ -15,12 +15,9 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.scalablegateway.api; | 16 | package org.onosproject.scalablegateway.api; |
17 | 17 | ||
18 | -import com.google.common.collect.ImmutableList; | ||
19 | import org.onlab.packet.Ip4Address; | 18 | import org.onlab.packet.Ip4Address; |
20 | import org.onosproject.net.DeviceId; | 19 | import org.onosproject.net.DeviceId; |
21 | 20 | ||
22 | -import java.util.List; | ||
23 | - | ||
24 | import static com.google.common.base.Preconditions.checkNotNull; | 21 | import static com.google.common.base.Preconditions.checkNotNull; |
25 | 22 | ||
26 | /** | 23 | /** |
... | @@ -28,13 +25,13 @@ import static com.google.common.base.Preconditions.checkNotNull; | ... | @@ -28,13 +25,13 @@ import static com.google.common.base.Preconditions.checkNotNull; |
28 | */ | 25 | */ |
29 | public final class GatewayNode { | 26 | public final class GatewayNode { |
30 | private final DeviceId gatewayDeviceId; | 27 | private final DeviceId gatewayDeviceId; |
31 | - private final List<String> gatewayExternalInterfaceNames; | 28 | + private final String gatewayExternalInterfaceName; |
32 | private final Ip4Address dataIpAddress; | 29 | private final Ip4Address dataIpAddress; |
33 | 30 | ||
34 | - private GatewayNode(DeviceId gatewayDeviceId, List<String> gatewayExternalInterfaceNames, | 31 | + private GatewayNode(DeviceId gatewayDeviceId, String gatewayExternalInterfaceName, |
35 | Ip4Address dataIpAddress) { | 32 | Ip4Address dataIpAddress) { |
36 | this.gatewayDeviceId = gatewayDeviceId; | 33 | this.gatewayDeviceId = gatewayDeviceId; |
37 | - this.gatewayExternalInterfaceNames = gatewayExternalInterfaceNames; | 34 | + this.gatewayExternalInterfaceName = gatewayExternalInterfaceName; |
38 | this.dataIpAddress = dataIpAddress; | 35 | this.dataIpAddress = dataIpAddress; |
39 | } | 36 | } |
40 | 37 | ||
... | @@ -48,12 +45,12 @@ public final class GatewayNode { | ... | @@ -48,12 +45,12 @@ public final class GatewayNode { |
48 | } | 45 | } |
49 | 46 | ||
50 | /** | 47 | /** |
51 | - * Returns the list of gateway`s interface names. | 48 | + * Returns the gateway`s interface name. |
52 | * | 49 | * |
53 | - * @return The list of interface names | 50 | + * @return The gateway`s interface name |
54 | */ | 51 | */ |
55 | - public List<String> getGatewayExternalInterfaceNames() { | 52 | + public String getGatewayExternalInterfaceName() { |
56 | - return ImmutableList.copyOf(gatewayExternalInterfaceNames); | 53 | + return gatewayExternalInterfaceName; |
57 | } | 54 | } |
58 | 55 | ||
59 | /** | 56 | /** |
... | @@ -80,7 +77,7 @@ public final class GatewayNode { | ... | @@ -80,7 +77,7 @@ public final class GatewayNode { |
80 | public static final class Builder { | 77 | public static final class Builder { |
81 | 78 | ||
82 | private DeviceId gatewayDeviceId; | 79 | private DeviceId gatewayDeviceId; |
83 | - private List<String> gatewayExternalInterfaceNames; | 80 | + private String gatewayExternalInterfaceName; |
84 | private Ip4Address dataIpAddress; | 81 | private Ip4Address dataIpAddress; |
85 | 82 | ||
86 | /** | 83 | /** |
... | @@ -95,13 +92,13 @@ public final class GatewayNode { | ... | @@ -95,13 +92,13 @@ public final class GatewayNode { |
95 | } | 92 | } |
96 | 93 | ||
97 | /** | 94 | /** |
98 | - * Sets the list of gateway`s interface names. | 95 | + * Sets the gateway`s interface name. |
99 | * | 96 | * |
100 | - * @param names The list of gateway`s interface name | 97 | + * @param name The gateway`s interface name |
101 | * @return Builder object | 98 | * @return Builder object |
102 | */ | 99 | */ |
103 | - public Builder gatewayExternalInterfaceNames(List<String> names) { | 100 | + public Builder gatewayExternalInterfaceName(String name) { |
104 | - this.gatewayExternalInterfaceNames = names; | 101 | + this.gatewayExternalInterfaceName = name; |
105 | return this; | 102 | return this; |
106 | } | 103 | } |
107 | 104 | ||
... | @@ -122,7 +119,7 @@ public final class GatewayNode { | ... | @@ -122,7 +119,7 @@ public final class GatewayNode { |
122 | * @return GatewayNode object | 119 | * @return GatewayNode object |
123 | */ | 120 | */ |
124 | public GatewayNode build() { | 121 | public GatewayNode build() { |
125 | - return new GatewayNode(checkNotNull(gatewayDeviceId), checkNotNull(gatewayExternalInterfaceNames), | 122 | + return new GatewayNode(checkNotNull(gatewayDeviceId), checkNotNull(gatewayExternalInterfaceName), |
126 | checkNotNull(dataIpAddress)); | 123 | checkNotNull(dataIpAddress)); |
127 | } | 124 | } |
128 | } | 125 | } | ... | ... |
... | @@ -18,7 +18,6 @@ package org.onosproject.scalablegateway.api; | ... | @@ -18,7 +18,6 @@ package org.onosproject.scalablegateway.api; |
18 | 18 | ||
19 | import com.fasterxml.jackson.databind.JsonNode; | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import com.fasterxml.jackson.databind.node.ObjectNode; | 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
21 | -import com.google.common.collect.Lists; | ||
22 | import com.google.common.collect.Sets; | 21 | import com.google.common.collect.Sets; |
23 | import org.onlab.packet.Ip4Address; | 22 | import org.onlab.packet.Ip4Address; |
24 | import org.onosproject.core.ApplicationId; | 23 | import org.onosproject.core.ApplicationId; |
... | @@ -26,8 +25,6 @@ import org.onosproject.net.DeviceId; | ... | @@ -26,8 +25,6 @@ import org.onosproject.net.DeviceId; |
26 | import org.onosproject.net.config.Config; | 25 | import org.onosproject.net.config.Config; |
27 | import org.slf4j.Logger; | 26 | import org.slf4j.Logger; |
28 | 27 | ||
29 | -import java.util.Collections; | ||
30 | -import java.util.List; | ||
31 | import java.util.Set; | 28 | import java.util.Set; |
32 | import java.util.stream.StreamSupport; | 29 | import java.util.stream.StreamSupport; |
33 | 30 | ||
... | @@ -64,8 +61,7 @@ public class GatewayNodeConfig extends Config<ApplicationId> { | ... | @@ -64,8 +61,7 @@ public class GatewayNodeConfig extends Config<ApplicationId> { |
64 | try { | 61 | try { |
65 | nodes.add(new GatewayNode.Builder() | 62 | nodes.add(new GatewayNode.Builder() |
66 | .gatewayDeviceId(DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText())) | 63 | .gatewayDeviceId(DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText())) |
67 | - .gatewayExternalInterfaceNames( | 64 | + .gatewayExternalInterfaceName(jsonNode.path(EXTERNAL_INTERFACE_NAME).asText()) |
68 | - getExternalInterfaceName(jsonNode.path(EXTERNAL_INTERFACE_NAME).asText())) | ||
69 | .dataIpAddress(Ip4Address.valueOf(jsonNode.path(DATAPLANE_IP).asText())).build()); | 65 | .dataIpAddress(Ip4Address.valueOf(jsonNode.path(DATAPLANE_IP).asText())).build()); |
70 | } catch (IllegalArgumentException | NullPointerException e) { | 66 | } catch (IllegalArgumentException | NullPointerException e) { |
71 | log.error("Failed to read {}", e.toString()); | 67 | log.error("Failed to read {}", e.toString()); |
... | @@ -74,11 +70,6 @@ public class GatewayNodeConfig extends Config<ApplicationId> { | ... | @@ -74,11 +70,6 @@ public class GatewayNodeConfig extends Config<ApplicationId> { |
74 | return nodes; | 70 | return nodes; |
75 | } | 71 | } |
76 | 72 | ||
77 | - private List<String> getExternalInterfaceName(String s) { | ||
78 | - List<String> list = Lists.newArrayList(); | ||
79 | - return Collections.addAll(list, s.split(",")) ? list : null; | ||
80 | - } | ||
81 | - | ||
82 | @Override | 73 | @Override |
83 | public boolean isValid() { | 74 | public boolean isValid() { |
84 | JsonNode jsonNodes = object.get(NODES); | 75 | JsonNode jsonNodes = object.get(NODES); | ... | ... |
... | @@ -35,12 +35,12 @@ public interface ScalableGatewayService { | ... | @@ -35,12 +35,12 @@ public interface ScalableGatewayService { |
35 | GatewayNode getGatewayNode(DeviceId deviceId); | 35 | GatewayNode getGatewayNode(DeviceId deviceId); |
36 | 36 | ||
37 | /** | 37 | /** |
38 | - * Returns the list of gateway`s port numbers with the given device identifier. | 38 | + * Returns the gateway`s port number with the given device identifier. |
39 | * | 39 | * |
40 | * @param deviceId The gateway node deviceId | 40 | * @param deviceId The gateway node deviceId |
41 | - * @return The list of external interface port number | 41 | + * @return The external interface port number |
42 | */ | 42 | */ |
43 | - List<PortNumber> getGatewayExternalPorts(DeviceId deviceId); | 43 | + PortNumber getGatewayExternalPort(DeviceId deviceId); |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * Returns group id for gateway load balance. | 46 | * Returns group id for gateway load balance. | ... | ... |
... | @@ -16,7 +16,6 @@ | ... | @@ -16,7 +16,6 @@ |
16 | 16 | ||
17 | package org.onosproject.scalablegateway.cli; | 17 | package org.onosproject.scalablegateway.cli; |
18 | 18 | ||
19 | -import com.google.common.collect.Lists; | ||
20 | import org.apache.karaf.shell.commands.Argument; | 19 | import org.apache.karaf.shell.commands.Argument; |
21 | import org.apache.karaf.shell.commands.Command; | 20 | import org.apache.karaf.shell.commands.Command; |
22 | import org.onlab.packet.Ip4Address; | 21 | import org.onlab.packet.Ip4Address; |
... | @@ -25,9 +24,6 @@ import org.onosproject.net.DeviceId; | ... | @@ -25,9 +24,6 @@ import org.onosproject.net.DeviceId; |
25 | import org.onosproject.scalablegateway.api.GatewayNode; | 24 | import org.onosproject.scalablegateway.api.GatewayNode; |
26 | import org.onosproject.scalablegateway.api.ScalableGatewayService; | 25 | import org.onosproject.scalablegateway.api.ScalableGatewayService; |
27 | 26 | ||
28 | -import java.util.Collections; | ||
29 | -import java.util.List; | ||
30 | - | ||
31 | /** | 27 | /** |
32 | * Adds gateway node information for scalablegateway node managements. | 28 | * Adds gateway node information for scalablegateway node managements. |
33 | */ | 29 | */ |
... | @@ -60,7 +56,7 @@ public class ScalableGatewayAddCommand extends AbstractShellCommand { | ... | @@ -60,7 +56,7 @@ public class ScalableGatewayAddCommand extends AbstractShellCommand { |
60 | GatewayNode gatewayNode = GatewayNode.builder() | 56 | GatewayNode gatewayNode = GatewayNode.builder() |
61 | .gatewayDeviceId(DeviceId.deviceId(deviceId)) | 57 | .gatewayDeviceId(DeviceId.deviceId(deviceId)) |
62 | .dataIpAddress(Ip4Address.valueOf(ipAddress)) | 58 | .dataIpAddress(Ip4Address.valueOf(ipAddress)) |
63 | - .gatewayExternalInterfaceNames(splitNameList(interfaceName)) | 59 | + .gatewayExternalInterfaceName(interfaceName) |
64 | .build(); | 60 | .build(); |
65 | if (service.addGatewayNode(gatewayNode)) { | 61 | if (service.addGatewayNode(gatewayNode)) { |
66 | print(SUCCESS); | 62 | print(SUCCESS); |
... | @@ -69,8 +65,4 @@ public class ScalableGatewayAddCommand extends AbstractShellCommand { | ... | @@ -69,8 +65,4 @@ public class ScalableGatewayAddCommand extends AbstractShellCommand { |
69 | } | 65 | } |
70 | } | 66 | } |
71 | 67 | ||
72 | - private List<String> splitNameList(String interfaceName) { | ||
73 | - List<String> list = Lists.newArrayList(); | ||
74 | - return Collections.addAll(list, interfaceName.split(",")) ? list : null; | ||
75 | - } | ||
76 | } | 68 | } | ... | ... |
... | @@ -35,6 +35,6 @@ public class ScalableGatewayListCommand extends AbstractShellCommand { | ... | @@ -35,6 +35,6 @@ public class ScalableGatewayListCommand extends AbstractShellCommand { |
35 | service.getGatewayNodes().forEach(node -> print(FORMAT, | 35 | service.getGatewayNodes().forEach(node -> print(FORMAT, |
36 | node.getGatewayDeviceId().toString(), | 36 | node.getGatewayDeviceId().toString(), |
37 | node.getDataIpAddress().toString(), | 37 | node.getDataIpAddress().toString(), |
38 | - node.getGatewayExternalInterfaceNames().toString())); | 38 | + node.getGatewayExternalInterfaceName().toString())); |
39 | } | 39 | } |
40 | } | 40 | } | ... | ... |
... | @@ -155,23 +155,16 @@ public class ScalableGatewayManager implements ScalableGatewayService { | ... | @@ -155,23 +155,16 @@ public class ScalableGatewayManager implements ScalableGatewayService { |
155 | } | 155 | } |
156 | 156 | ||
157 | @Override | 157 | @Override |
158 | - public List<PortNumber> getGatewayExternalPorts(DeviceId deviceId) { | 158 | + public PortNumber getGatewayExternalPort(DeviceId deviceId) { |
159 | GatewayNode gatewayNode = checkNotNull(gatewayNodeMap.get(deviceId).value(), GATEWAYNODE_CAN_NOT_BE_NULL); | 159 | GatewayNode gatewayNode = checkNotNull(gatewayNodeMap.get(deviceId).value(), GATEWAYNODE_CAN_NOT_BE_NULL); |
160 | - List<PortNumber> portNumbers = Lists.newArrayList(); | 160 | + String externalInterfaceName = gatewayNode.getGatewayExternalInterfaceName(); |
161 | - gatewayNode.getGatewayExternalInterfaceNames() | 161 | + Optional<Port> port = deviceService.getPorts(deviceId) |
162 | .stream() | 162 | .stream() |
163 | - .forEach(name -> portNumbers.add(findPortNumFromPortName(gatewayNode.getGatewayDeviceId(), name))); | 163 | + .filter(p -> p.annotations().value(PORT_NAME).equals(externalInterfaceName)) |
164 | - return portNumbers; | ||
165 | - } | ||
166 | - | ||
167 | - private PortNumber findPortNumFromPortName(DeviceId gatewayDeviceId, String name) { | ||
168 | - Optional<Port> port = deviceService.getPorts(gatewayDeviceId) | ||
169 | - .stream() | ||
170 | - .filter(p -> p.annotations().value(PORT_NAME).equals(name)) | ||
171 | .findFirst(); | 164 | .findFirst(); |
172 | 165 | ||
173 | if (!port.isPresent()) { | 166 | if (!port.isPresent()) { |
174 | - log.error("Cannot find port {} in gateway device {}", name, gatewayDeviceId); | 167 | + log.error("Cannot find port {} in gateway device {}", externalInterfaceName, deviceId); |
175 | return null; | 168 | return null; |
176 | } | 169 | } |
177 | 170 | ... | ... |
-
Please register or login to post a comment