Hyunsun Moon
Committed by Gerrit Code Review

Fixed to not to create gateway group if it is already exists

Also changed some names shorter.

Change-Id: Iaa8aa5ac378fc168e79c9e238090ca817af42261
...@@ -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.getGatewayExternalPort(deviceId))); 334 + externalInfoMap.putIfAbsent(deviceId, gatewayService.getUplinkPort(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.getGatewayExternalInterfaceName() == null) { 150 + if (gatewayNode.getUplinkIntf() == 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.getGatewayExternalPort(deviceId)); 154 + treatment.setOutput(gatewayService.getUplinkPort(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.getGatewayExternalPort(deviceId)); 471 + gatewayService.getUplinkPort(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.getGatewayExternalPort(node.getGatewayDeviceId())); 191 + tBuilder.setOutput(gatewayService.getUplinkPort(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())
...@@ -380,7 +380,7 @@ public class OpenstackRoutingRulePopulator { ...@@ -380,7 +380,7 @@ public class OpenstackRoutingRulePopulator {
380 StreamSupport.stream(deviceService.getDevices().spliterator(), false) 380 StreamSupport.stream(deviceService.getDevices().spliterator(), false)
381 .filter(d -> isTypeOf(d.id(), OpenstackNodeService.NodeType.COMPUTE)) 381 .filter(d -> isTypeOf(d.id(), OpenstackNodeService.NodeType.COMPUTE))
382 .forEach(d -> populateRuleToGatewayBySgw(d.id(), 382 .forEach(d -> populateRuleToGatewayBySgw(d.id(),
383 - gatewayService.getGroupIdForGatewayLoadBalance(d.id()), vni)); 383 + gatewayService.getGatewayGroupId(d.id()), vni));
384 } 384 }
385 385
386 private void populateRuleToGatewayBySgw(DeviceId deviceId, GroupId groupId, long vni) { 386 private void populateRuleToGatewayBySgw(DeviceId deviceId, GroupId groupId, long vni) {
...@@ -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.getGatewayExternalPort(deviceId), PORTNOTNULL); 551 + return checkNotNull(gatewayService.getUplinkPort(deviceId), PORTNOTNULL);
552 } 552 }
553 553
554 /** 554 /**
......
...@@ -28,13 +28,12 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -28,13 +28,12 @@ import static com.google.common.base.Preconditions.checkNotNull;
28 */ 28 */
29 public final class GatewayNode { 29 public final class GatewayNode {
30 private final DeviceId gatewayDeviceId; 30 private final DeviceId gatewayDeviceId;
31 - private final String gatewayExternalInterfaceName; 31 + private final String uplinkIntf;
32 private final Ip4Address dataIpAddress; 32 private final Ip4Address dataIpAddress;
33 33
34 - private GatewayNode(DeviceId gatewayDeviceId, String gatewayExternalInterfaceName, 34 + private GatewayNode(DeviceId gatewayDeviceId, String uplinkIntf, Ip4Address dataIpAddress) {
35 - Ip4Address dataIpAddress) {
36 this.gatewayDeviceId = gatewayDeviceId; 35 this.gatewayDeviceId = gatewayDeviceId;
37 - this.gatewayExternalInterfaceName = gatewayExternalInterfaceName; 36 + this.uplinkIntf = uplinkIntf;
38 this.dataIpAddress = dataIpAddress; 37 this.dataIpAddress = dataIpAddress;
39 } 38 }
40 39
...@@ -52,8 +51,8 @@ public final class GatewayNode { ...@@ -52,8 +51,8 @@ public final class GatewayNode {
52 * 51 *
53 * @return The gateway`s interface name 52 * @return The gateway`s interface name
54 */ 53 */
55 - public String getGatewayExternalInterfaceName() { 54 + public String getUplinkIntf() {
56 - return gatewayExternalInterfaceName; 55 + return uplinkIntf;
57 } 56 }
58 57
59 /** 58 /**
...@@ -74,8 +73,7 @@ public final class GatewayNode { ...@@ -74,8 +73,7 @@ public final class GatewayNode {
74 if (obj instanceof GatewayNode) { 73 if (obj instanceof GatewayNode) {
75 GatewayNode that = (GatewayNode) obj; 74 GatewayNode that = (GatewayNode) obj;
76 if (Objects.equals(gatewayDeviceId, that.gatewayDeviceId) && 75 if (Objects.equals(gatewayDeviceId, that.gatewayDeviceId) &&
77 - Objects.equals(gatewayExternalInterfaceName, 76 + Objects.equals(uplinkIntf, that.uplinkIntf) &&
78 - that.gatewayExternalInterfaceName) &&
79 Objects.equals(dataIpAddress, that.dataIpAddress)) { 77 Objects.equals(dataIpAddress, that.dataIpAddress)) {
80 return true; 78 return true;
81 } 79 }
...@@ -85,17 +83,15 @@ public final class GatewayNode { ...@@ -85,17 +83,15 @@ public final class GatewayNode {
85 83
86 @Override 84 @Override
87 public int hashCode() { 85 public int hashCode() {
88 - return Objects.hash(gatewayDeviceId, 86 + return Objects.hash(gatewayDeviceId, uplinkIntf, dataIpAddress);
89 - gatewayExternalInterfaceName,
90 - dataIpAddress);
91 } 87 }
92 88
93 @Override 89 @Override
94 public String toString() { 90 public String toString() {
95 return MoreObjects.toStringHelper(getClass()) 91 return MoreObjects.toStringHelper(getClass())
96 - .add("deviceId", gatewayDeviceId) 92 + .add("gatewayDeviceId", gatewayDeviceId)
97 - .add("externalPort", gatewayExternalInterfaceName) 93 + .add("uplinkInterface", uplinkIntf)
98 - .add("dataIp", dataIpAddress) 94 + .add("dataIpAddress", dataIpAddress)
99 .toString(); 95 .toString();
100 } 96 }
101 97
...@@ -114,7 +110,7 @@ public final class GatewayNode { ...@@ -114,7 +110,7 @@ public final class GatewayNode {
114 public static final class Builder { 110 public static final class Builder {
115 111
116 private DeviceId gatewayDeviceId; 112 private DeviceId gatewayDeviceId;
117 - private String gatewayExternalInterfaceName; 113 + private String uplinkIntf;
118 private Ip4Address dataIpAddress; 114 private Ip4Address dataIpAddress;
119 115
120 /** 116 /**
...@@ -129,13 +125,13 @@ public final class GatewayNode { ...@@ -129,13 +125,13 @@ public final class GatewayNode {
129 } 125 }
130 126
131 /** 127 /**
132 - * Sets the gateway`s interface name. 128 + * Sets the gateway`s uplink interface name.
133 * 129 *
134 * @param name The gateway`s interface name 130 * @param name The gateway`s interface name
135 * @return Builder object 131 * @return Builder object
136 */ 132 */
137 - public Builder gatewayExternalInterfaceName(String name) { 133 + public Builder uplinkIntf(String name) {
138 - this.gatewayExternalInterfaceName = name; 134 + this.uplinkIntf = name;
139 return this; 135 return this;
140 } 136 }
141 137
...@@ -156,8 +152,8 @@ public final class GatewayNode { ...@@ -156,8 +152,8 @@ public final class GatewayNode {
156 * @return GatewayNode object 152 * @return GatewayNode object
157 */ 153 */
158 public GatewayNode build() { 154 public GatewayNode build() {
159 - return new GatewayNode(checkNotNull(gatewayDeviceId), checkNotNull(gatewayExternalInterfaceName), 155 + return new GatewayNode(checkNotNull(gatewayDeviceId), checkNotNull(uplinkIntf),
160 - checkNotNull(dataIpAddress)); 156 + checkNotNull(dataIpAddress));
161 } 157 }
162 } 158 }
163 } 159 }
......
...@@ -41,7 +41,7 @@ public class GatewayNodeConfig extends Config<ApplicationId> { ...@@ -41,7 +41,7 @@ public class GatewayNodeConfig extends Config<ApplicationId> {
41 public static final String NODES = "nodes"; 41 public static final String NODES = "nodes";
42 public static final String BRIDGE_ID = "bridgeId"; 42 public static final String BRIDGE_ID = "bridgeId";
43 public static final String DATAPLANE_IP = "dataPlaneIp"; 43 public static final String DATAPLANE_IP = "dataPlaneIp";
44 - public static final String EXTERNAL_INTERFACE_NAME = "gatewayExternalInterfaceName"; 44 + public static final String UPLINK_INTERFACE_NAME = "uplinkInterface";
45 45
46 /** 46 /**
47 * Returns the set of nodes read from network config. 47 * Returns the set of nodes read from network config.
...@@ -61,7 +61,7 @@ public class GatewayNodeConfig extends Config<ApplicationId> { ...@@ -61,7 +61,7 @@ public class GatewayNodeConfig extends Config<ApplicationId> {
61 try { 61 try {
62 nodes.add(new GatewayNode.Builder() 62 nodes.add(new GatewayNode.Builder()
63 .gatewayDeviceId(DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText())) 63 .gatewayDeviceId(DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText()))
64 - .gatewayExternalInterfaceName(jsonNode.path(EXTERNAL_INTERFACE_NAME).asText()) 64 + .uplinkIntf(jsonNode.path(UPLINK_INTERFACE_NAME).asText())
65 .dataIpAddress(Ip4Address.valueOf(jsonNode.path(DATAPLANE_IP).asText())).build()); 65 .dataIpAddress(Ip4Address.valueOf(jsonNode.path(DATAPLANE_IP).asText())).build());
66 } catch (IllegalArgumentException | NullPointerException e) { 66 } catch (IllegalArgumentException | NullPointerException e) {
67 log.error("Failed to read {}", e.toString()); 67 log.error("Failed to read {}", e.toString());
...@@ -86,7 +86,7 @@ public class GatewayNodeConfig extends Config<ApplicationId> { ...@@ -86,7 +86,7 @@ public class GatewayNodeConfig extends Config<ApplicationId> {
86 ObjectNode objectNode = (ObjectNode) jsonNode; 86 ObjectNode objectNode = (ObjectNode) jsonNode;
87 return isString(objectNode, BRIDGE_ID, MANDATORY) 87 return isString(objectNode, BRIDGE_ID, MANDATORY)
88 && isIpAddress(objectNode, DATAPLANE_IP, MANDATORY) 88 && isIpAddress(objectNode, DATAPLANE_IP, MANDATORY)
89 - && isString(objectNode, EXTERNAL_INTERFACE_NAME, MANDATORY); 89 + && isString(objectNode, UPLINK_INTERFACE_NAME, MANDATORY);
90 } 90 }
91 91
92 } 92 }
......
...@@ -35,20 +35,21 @@ public interface ScalableGatewayService { ...@@ -35,20 +35,21 @@ public interface ScalableGatewayService {
35 GatewayNode getGatewayNode(DeviceId deviceId); 35 GatewayNode getGatewayNode(DeviceId deviceId);
36 36
37 /** 37 /**
38 - * Returns the gateway`s port number with the given device identifier. 38 + * Returns the uplink port number of the gateway with the supplied device ID.
39 * 39 *
40 - * @param deviceId The gateway node deviceId 40 + * @param deviceId the gateway node device id
41 - * @return The external interface port number 41 + * @return the external interface port number
42 */ 42 */
43 - PortNumber getGatewayExternalPort(DeviceId deviceId); 43 + PortNumber getUplinkPort(DeviceId deviceId);
44 44
45 /** 45 /**
46 * Returns group id for gateway load balance. 46 * Returns group id for gateway load balance.
47 + * If the group does not exist in the supplied source device, creates one.
47 * 48 *
48 * @param srcDeviceId source device id 49 * @param srcDeviceId source device id
49 * @return The group id 50 * @return The group id
50 */ 51 */
51 - GroupId getGroupIdForGatewayLoadBalance(DeviceId srcDeviceId); 52 + GroupId getGatewayGroupId(DeviceId srcDeviceId);
52 53
53 /** 54 /**
54 * Returns the list of gateway node information with the given device identifier. 55 * Returns the list of gateway node information with the given device identifier.
......
...@@ -56,7 +56,7 @@ public class ScalableGatewayAddCommand extends AbstractShellCommand { ...@@ -56,7 +56,7 @@ public class ScalableGatewayAddCommand extends AbstractShellCommand {
56 GatewayNode gatewayNode = GatewayNode.builder() 56 GatewayNode gatewayNode = GatewayNode.builder()
57 .gatewayDeviceId(DeviceId.deviceId(deviceId)) 57 .gatewayDeviceId(DeviceId.deviceId(deviceId))
58 .dataIpAddress(Ip4Address.valueOf(ipAddress)) 58 .dataIpAddress(Ip4Address.valueOf(ipAddress))
59 - .gatewayExternalInterfaceName(interfaceName) 59 + .uplinkIntf(interfaceName)
60 .build(); 60 .build();
61 if (service.addGatewayNode(gatewayNode)) { 61 if (service.addGatewayNode(gatewayNode)) {
62 print(SUCCESS); 62 print(SUCCESS);
......
...@@ -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.getGatewayExternalInterfaceName().toString())); 38 + node.getUplinkIntf().toString()));
39 } 39 }
40 } 40 }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onosproject.scalablegateway.impl; 17 package org.onosproject.scalablegateway.impl;
18 18
19 +import com.google.common.collect.ImmutableList;
19 import com.google.common.collect.Lists; 20 import com.google.common.collect.Lists;
20 import org.apache.felix.scr.annotations.Activate; 21 import org.apache.felix.scr.annotations.Activate;
21 import org.apache.felix.scr.annotations.Component; 22 import org.apache.felix.scr.annotations.Component;
...@@ -25,6 +26,7 @@ import org.apache.felix.scr.annotations.Reference; ...@@ -25,6 +26,7 @@ import org.apache.felix.scr.annotations.Reference;
25 import org.apache.felix.scr.annotations.ReferenceCardinality; 26 import org.apache.felix.scr.annotations.ReferenceCardinality;
26 import org.apache.felix.scr.annotations.Service; 27 import org.apache.felix.scr.annotations.Service;
27 import org.onlab.util.KryoNamespace; 28 import org.onlab.util.KryoNamespace;
29 +import org.onlab.util.Tools;
28 import org.onosproject.core.ApplicationId; 30 import org.onosproject.core.ApplicationId;
29 import org.onosproject.core.CoreService; 31 import org.onosproject.core.CoreService;
30 32
...@@ -43,13 +45,14 @@ import org.onosproject.net.device.DeviceListener; ...@@ -43,13 +45,14 @@ import org.onosproject.net.device.DeviceListener;
43 import org.onosproject.net.device.DeviceService; 45 import org.onosproject.net.device.DeviceService;
44 import org.onosproject.net.driver.DriverService; 46 import org.onosproject.net.driver.DriverService;
45 import org.onosproject.net.group.Group; 47 import org.onosproject.net.group.Group;
46 -import org.onosproject.net.group.GroupDescription; 48 +import org.onosproject.net.group.GroupKey;
47 import org.onosproject.net.group.GroupService; 49 import org.onosproject.net.group.GroupService;
48 import org.onosproject.scalablegateway.api.GatewayNode; 50 import org.onosproject.scalablegateway.api.GatewayNode;
49 import org.onosproject.scalablegateway.api.GatewayNodeConfig; 51 import org.onosproject.scalablegateway.api.GatewayNodeConfig;
50 import org.onosproject.scalablegateway.api.ScalableGatewayService; 52 import org.onosproject.scalablegateway.api.ScalableGatewayService;
51 53
52 import java.util.List; 54 import java.util.List;
55 +import java.util.Objects;
53 import java.util.Optional; 56 import java.util.Optional;
54 57
55 import org.onosproject.store.serializers.KryoNamespaces; 58 import org.onosproject.store.serializers.KryoNamespaces;
...@@ -60,7 +63,7 @@ import org.onosproject.store.service.Versioned; ...@@ -60,7 +63,7 @@ import org.onosproject.store.service.Versioned;
60 import org.slf4j.Logger; 63 import org.slf4j.Logger;
61 import org.slf4j.LoggerFactory; 64 import org.slf4j.LoggerFactory;
62 65
63 -import static com.google.common.base.Preconditions.checkNotNull; 66 +import static org.onosproject.net.AnnotationKeys.PORT_NAME;
64 67
65 /** 68 /**
66 * Manages gateway node for gateway scalability. 69 * Manages gateway node for gateway scalability.
...@@ -74,11 +77,6 @@ public class ScalableGatewayManager implements ScalableGatewayService { ...@@ -74,11 +77,6 @@ public class ScalableGatewayManager implements ScalableGatewayService {
74 private ApplicationId appId; 77 private ApplicationId appId;
75 private static final String APP_ID = "org.onosproject.scalablegateway"; 78 private static final String APP_ID = "org.onosproject.scalablegateway";
76 private static final String APP_NAME = "scalablegateway"; 79 private static final String APP_NAME = "scalablegateway";
77 - private static final String GATEWAYNODE_CAN_NOT_BE_NULL = "The gateway node can not be null";
78 - private static final String PORT_CAN_NOT_BE_NULL = "The port can not be null";
79 - private static final String FAIL_ADD_GATEWAY = "Adding process is failed as existing deivce id";
80 - private static final String FAIL_REMOVE_GATEWAY = "Removing process is failed as unknown deivce id";
81 - private static final String PORT_NAME = "portName";
82 private static final String GATEWAYNODE_MAP_NAME = "gatewaynode-map"; 80 private static final String GATEWAYNODE_MAP_NAME = "gatewaynode-map";
83 81
84 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 82 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -106,7 +104,7 @@ public class ScalableGatewayManager implements ScalableGatewayService { ...@@ -106,7 +104,7 @@ public class ScalableGatewayManager implements ScalableGatewayService {
106 private SelectGroupHandler selectGroupHandler; 104 private SelectGroupHandler selectGroupHandler;
107 105
108 private final NetworkConfigListener configListener = new InternalConfigListener(); 106 private final NetworkConfigListener configListener = new InternalConfigListener();
109 - private InternalDeviceListener internalDeviceListener = new InternalDeviceListener(); 107 + private final InternalDeviceListener internalDeviceListener = new InternalDeviceListener();
110 108
111 private final ConfigFactory configFactory = 109 private final ConfigFactory configFactory =
112 new ConfigFactory(SubjectFactories.APP_SUBJECT_FACTORY, GatewayNodeConfig.class, APP_NAME) { 110 new ConfigFactory(SubjectFactories.APP_SUBJECT_FACTORY, GatewayNodeConfig.class, APP_NAME) {
...@@ -115,10 +113,10 @@ public class ScalableGatewayManager implements ScalableGatewayService { ...@@ -115,10 +113,10 @@ public class ScalableGatewayManager implements ScalableGatewayService {
115 return new GatewayNodeConfig(); 113 return new GatewayNodeConfig();
116 } 114 }
117 }; 115 };
118 - private ConsistentMap<DeviceId, GatewayNode> gatewayNodeMap; // Map<GatewayNode`s Id, GatewayNode object> 116 +
117 + private ConsistentMap<DeviceId, GatewayNode> gatewayNodeMap; // Map<GatewayNode Id, GatewayNode object>
119 private static final KryoNamespace.Builder GATEWAYNODE_SERIALIZER = KryoNamespace.newBuilder() 118 private static final KryoNamespace.Builder GATEWAYNODE_SERIALIZER = KryoNamespace.newBuilder()
120 .register(KryoNamespaces.API) 119 .register(KryoNamespaces.API)
121 - .register(DeviceId.class)
122 .register(GatewayNode.class); 120 .register(GatewayNode.class);
123 121
124 @Activate 122 @Activate
...@@ -141,8 +139,6 @@ public class ScalableGatewayManager implements ScalableGatewayService { ...@@ -141,8 +139,6 @@ public class ScalableGatewayManager implements ScalableGatewayService {
141 139
142 @Deactivate 140 @Deactivate
143 protected void deactivate() { 141 protected void deactivate() {
144 - gatewayNodeMap.clear();
145 -
146 deviceService.removeListener(internalDeviceListener); 142 deviceService.removeListener(internalDeviceListener);
147 configService.removeListener(configListener); 143 configService.removeListener(configListener);
148 144
...@@ -151,32 +147,44 @@ public class ScalableGatewayManager implements ScalableGatewayService { ...@@ -151,32 +147,44 @@ public class ScalableGatewayManager implements ScalableGatewayService {
151 147
152 @Override 148 @Override
153 public GatewayNode getGatewayNode(DeviceId deviceId) { 149 public GatewayNode getGatewayNode(DeviceId deviceId) {
154 - return checkNotNull(gatewayNodeMap.get(deviceId).value(), GATEWAYNODE_CAN_NOT_BE_NULL); 150 + GatewayNode gatewayNode = gatewayNodeMap.get(deviceId).value();
151 + if (gatewayNode == null) {
152 + log.warn("Gateway with device ID {} does not exist");
153 + return null;
154 + }
155 + return gatewayNode;
155 } 156 }
156 157
157 @Override 158 @Override
158 - public PortNumber getGatewayExternalPort(DeviceId deviceId) { 159 + public PortNumber getUplinkPort(DeviceId deviceId) {
159 - GatewayNode gatewayNode = checkNotNull(gatewayNodeMap.get(deviceId).value(), GATEWAYNODE_CAN_NOT_BE_NULL); 160 + GatewayNode gatewayNode = gatewayNodeMap.get(deviceId).value();
160 - String externalInterfaceName = gatewayNode.getGatewayExternalInterfaceName(); 161 + if (gatewayNode == null) {
161 - Optional<Port> port = deviceService.getPorts(deviceId) 162 + log.warn("Gateway with device ID {} does not exist");
162 - .stream() 163 + return null;
163 - .filter(p -> p.annotations().value(PORT_NAME).equals(externalInterfaceName)) 164 + }
164 - .findFirst();
165 165
166 + Optional<Port> port = deviceService.getPorts(deviceId).stream()
167 + .filter(p -> Objects.equals(
168 + p.annotations().value(PORT_NAME),
169 + gatewayNode.getUplinkIntf()))
170 + .findFirst();
166 if (!port.isPresent()) { 171 if (!port.isPresent()) {
167 - log.error("Cannot find port {} in gateway device {}", externalInterfaceName, deviceId); 172 + log.warn("Cannot find uplink interface from gateway {}", deviceId);
168 return null; 173 return null;
169 } 174 }
170 -
171 return port.get().number(); 175 return port.get().number();
172 } 176 }
173 177
174 @Override 178 @Override
175 - public GroupId getGroupIdForGatewayLoadBalance(DeviceId srcDeviceId) { 179 + public synchronized GroupId getGatewayGroupId(DeviceId srcDeviceId) {
176 - GroupDescription description = selectGroupHandler.createSelectGroupInVxlan(srcDeviceId, getGatewayNodes()); 180 + GroupKey groupKey = selectGroupHandler.getGroupKey(srcDeviceId);
177 - groupService.addGroup(description); 181 + Group group = groupService.getGroup(srcDeviceId, groupKey);
178 - Group group = groupService.getGroup(description.deviceId(), description.appCookie()); 182 + if (group == null) {
179 - return group != null ? group.id() : null; 183 + log.info("Created gateway group for {}", srcDeviceId);
184 + return selectGroupHandler.createGatewayGroup(srcDeviceId, getGatewayNodes());
185 + } else {
186 + return group.id();
187 + }
180 } 188 }
181 189
182 @Override 190 @Override
...@@ -185,9 +193,8 @@ public class ScalableGatewayManager implements ScalableGatewayService { ...@@ -185,9 +193,8 @@ public class ScalableGatewayManager implements ScalableGatewayService {
185 gatewayNodeMap.values() 193 gatewayNodeMap.values()
186 .stream() 194 .stream()
187 .map(Versioned::value) 195 .map(Versioned::value)
188 - .forEach(gatewayNode -> gatewayNodeList.add(gatewayNode)); 196 + .forEach(gatewayNodeList::add);
189 return gatewayNodeList; 197 return gatewayNodeList;
190 -
191 } 198 }
192 199
193 @Override 200 @Override
...@@ -198,7 +205,6 @@ public class ScalableGatewayManager implements ScalableGatewayService { ...@@ -198,7 +205,6 @@ public class ScalableGatewayManager implements ScalableGatewayService {
198 .map(Versioned::value) 205 .map(Versioned::value)
199 .forEach(gatewayNode -> deviceIdList.add(gatewayNode.getGatewayDeviceId())); 206 .forEach(gatewayNode -> deviceIdList.add(gatewayNode.getGatewayDeviceId()));
200 return deviceIdList; 207 return deviceIdList;
201 -
202 } 208 }
203 209
204 @Override 210 @Override
...@@ -206,7 +212,7 @@ public class ScalableGatewayManager implements ScalableGatewayService { ...@@ -206,7 +212,7 @@ public class ScalableGatewayManager implements ScalableGatewayService {
206 Versioned<GatewayNode> existingNode = gatewayNodeMap.putIfAbsent( 212 Versioned<GatewayNode> existingNode = gatewayNodeMap.putIfAbsent(
207 gatewayNode.getGatewayDeviceId(), gatewayNode); 213 gatewayNode.getGatewayDeviceId(), gatewayNode);
208 if (existingNode == null) { 214 if (existingNode == null) {
209 - updateGatewayLoadBalance(gatewayNode, true); 215 + updateGatewayGroup(gatewayNode, true);
210 log.info("Added {} to gateway pool", gatewayNode); 216 log.info("Added {} to gateway pool", gatewayNode);
211 return true; 217 return true;
212 } else { 218 } else {
...@@ -218,16 +224,22 @@ public class ScalableGatewayManager implements ScalableGatewayService { ...@@ -218,16 +224,22 @@ public class ScalableGatewayManager implements ScalableGatewayService {
218 public boolean deleteGatewayNode(GatewayNode gatewayNode) { 224 public boolean deleteGatewayNode(GatewayNode gatewayNode) {
219 boolean result = gatewayNodeMap.remove(gatewayNode.getGatewayDeviceId(), gatewayNode); 225 boolean result = gatewayNodeMap.remove(gatewayNode.getGatewayDeviceId(), gatewayNode);
220 if (result) { 226 if (result) {
221 - updateGatewayLoadBalance(gatewayNode, false); 227 + updateGatewayGroup(gatewayNode, false);
228 + log.info("Deleted gateway with device ID {}", gatewayNode.getGatewayDeviceId());
222 } 229 }
223 return result; 230 return result;
224 } 231 }
225 232
226 - private void updateGatewayLoadBalance(GatewayNode gatewayNode, boolean nodeInsertion) { 233 + private void updateGatewayGroup(GatewayNode gatewayNode, boolean isInsert) {
227 - deviceService.getAvailableDevices().forEach(device -> 234 + Tools.stream(deviceService.getAvailableDevices()).forEach(device -> {
228 - groupService.getGroups(device.id(), appId).forEach(group -> 235 + Tools.stream(groupService.getGroups(device.id(), appId)).forEach(group -> {
229 - selectGroupHandler.updateBucketToSelectGroupInVxlan(device.id(), group.appCookie(), 236 + selectGroupHandler.updateGatewayGroupBuckets(
230 - Lists.newArrayList(gatewayNode), nodeInsertion))); 237 + device.id(),
238 + ImmutableList.of(gatewayNode),
239 + isInsert);
240 + log.trace("Updated gateway group on {}", device.id());
241 + });
242 + });
231 } 243 }
232 244
233 private class InternalConfigListener implements NetworkConfigListener { 245 private class InternalConfigListener implements NetworkConfigListener {
...@@ -257,7 +269,9 @@ public class ScalableGatewayManager implements ScalableGatewayService { ...@@ -257,7 +269,9 @@ public class ScalableGatewayManager implements ScalableGatewayService {
257 public void event(DeviceEvent deviceEvent) { 269 public void event(DeviceEvent deviceEvent) {
258 if (deviceEvent.type() == DeviceEvent.Type.DEVICE_SUSPENDED || 270 if (deviceEvent.type() == DeviceEvent.Type.DEVICE_SUSPENDED ||
259 deviceEvent.type() == DeviceEvent.Type.DEVICE_REMOVED) { 271 deviceEvent.type() == DeviceEvent.Type.DEVICE_REMOVED) {
260 - deleteGatewayNode(getGatewayNode(deviceEvent.subject().id())); 272 + DeviceId deviceId = deviceEvent.subject().id();
273 + deleteGatewayNode(getGatewayNode(deviceId));
274 + log.warn("Gateway with device ID {} is disconnected", deviceId);
261 } 275 }
262 } 276 }
263 } 277 }
...@@ -269,8 +283,7 @@ public class ScalableGatewayManager implements ScalableGatewayService { ...@@ -269,8 +283,7 @@ public class ScalableGatewayManager implements ScalableGatewayService {
269 return; 283 return;
270 } 284 }
271 285
272 - config.gatewayNodes().forEach(gatewayNode -> addGatewayNode(gatewayNode)); 286 + config.gatewayNodes().forEach(this::addGatewayNode);
273 -
274 log.info("ScalableGateway configured"); 287 log.info("ScalableGateway configured");
275 } 288 }
276 } 289 }
......
...@@ -19,6 +19,8 @@ package org.onosproject.scalablegateway.impl; ...@@ -19,6 +19,8 @@ package org.onosproject.scalablegateway.impl;
19 import com.google.common.collect.Lists; 19 import com.google.common.collect.Lists;
20 import org.onlab.packet.Ip4Address; 20 import org.onlab.packet.Ip4Address;
21 import org.onosproject.core.ApplicationId; 21 import org.onosproject.core.ApplicationId;
22 +import org.onosproject.core.DefaultGroupId;
23 +import org.onosproject.core.GroupId;
22 import org.onosproject.net.DeviceId; 24 import org.onosproject.net.DeviceId;
23 import org.onosproject.net.Port; 25 import org.onosproject.net.Port;
24 import org.onosproject.net.PortNumber; 26 import org.onosproject.net.PortNumber;
...@@ -36,7 +38,6 @@ import org.onosproject.net.flow.instructions.ExtensionTreatment; ...@@ -36,7 +38,6 @@ import org.onosproject.net.flow.instructions.ExtensionTreatment;
36 import org.onosproject.net.flow.instructions.ExtensionTreatmentType; 38 import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
37 import org.onosproject.net.group.DefaultGroupDescription; 39 import org.onosproject.net.group.DefaultGroupDescription;
38 import org.onosproject.net.group.DefaultGroupKey; 40 import org.onosproject.net.group.DefaultGroupKey;
39 -import org.onosproject.net.group.Group;
40 import org.onosproject.net.group.GroupBucket; 41 import org.onosproject.net.group.GroupBucket;
41 import org.onosproject.net.group.GroupBuckets; 42 import org.onosproject.net.group.GroupBuckets;
42 import org.onosproject.net.group.GroupDescription; 43 import org.onosproject.net.group.GroupDescription;
...@@ -48,6 +49,7 @@ import org.slf4j.LoggerFactory; ...@@ -48,6 +49,7 @@ import org.slf4j.LoggerFactory;
48 49
49 import java.util.List; 50 import java.util.List;
50 51
52 +import static org.onosproject.net.AnnotationKeys.PORT_NAME;
51 import static org.onosproject.net.group.DefaultGroupBucket.createSelectGroupBucket; 53 import static org.onosproject.net.group.DefaultGroupBucket.createSelectGroupBucket;
52 54
53 /** 55 /**
...@@ -59,7 +61,6 @@ public class SelectGroupHandler { ...@@ -59,7 +61,6 @@ public class SelectGroupHandler {
59 61
60 private static final String TUNNEL_DESTINATION = "tunnelDst"; 62 private static final String TUNNEL_DESTINATION = "tunnelDst";
61 private static final String PORTNAME_PREFIX_TUNNEL = "vxlan"; 63 private static final String PORTNAME_PREFIX_TUNNEL = "vxlan";
62 - private static final String PORTNAME = "portName";
63 64
64 private final GroupService groupService; 65 private final GroupService groupService;
65 private final DeviceService deviceService; 66 private final DeviceService deviceService;
...@@ -89,45 +90,61 @@ public class SelectGroupHandler { ...@@ -89,45 +90,61 @@ public class SelectGroupHandler {
89 * @param nodeList gateway node list for bucket action 90 * @param nodeList gateway node list for bucket action
90 * @return created select type group description 91 * @return created select type group description
91 */ 92 */
92 - public GroupDescription createSelectGroupInVxlan(DeviceId srcDeviceId, List<GatewayNode> nodeList) { 93 + public GroupId createGatewayGroup(DeviceId srcDeviceId, List<GatewayNode> nodeList) {
93 List<GroupBucket> bucketList = generateBucketsForSelectGroup(srcDeviceId, nodeList); 94 List<GroupBucket> bucketList = generateBucketsForSelectGroup(srcDeviceId, nodeList);
94 - GroupKey key = generateGroupKey(srcDeviceId, nodeList); 95 + GroupId groupId = getGroupId(srcDeviceId);
95 - return new DefaultGroupDescription(srcDeviceId, GroupDescription.Type.SELECT, 96 + GroupDescription groupDescription = new DefaultGroupDescription(
96 - new GroupBuckets(bucketList), key, null, appId); 97 + srcDeviceId,
98 + GroupDescription.Type.SELECT,
99 + new GroupBuckets(bucketList),
100 + getGroupKey(srcDeviceId),
101 + groupId.id(),
102 + appId);
103 +
104 + groupService.addGroup(groupDescription);
105 + return groupId;
97 } 106 }
98 107
99 - private GroupKey generateGroupKey(DeviceId srcDeviceId, List<GatewayNode> nodeList) { 108 + /**
100 - String cookie = srcDeviceId.toString(); 109 + * Returns unique group key with supplied source device ID as a hash.
101 - for (GatewayNode node : nodeList) { 110 + *
102 - cookie = cookie.concat(node.getGatewayDeviceId().toString()); 111 + * @param srcDeviceId source device id
103 - } 112 + * @return group key
104 - return new DefaultGroupKey(cookie.getBytes()); 113 + */
114 + public GroupKey getGroupKey(DeviceId srcDeviceId) {
115 + return new DefaultGroupKey(srcDeviceId.toString().getBytes());
116 + }
105 117
118 + private GroupId getGroupId(DeviceId srcDeviceId) {
119 + return new DefaultGroupId(srcDeviceId.toString().hashCode());
106 } 120 }
107 121
108 /** 122 /**
109 * Updates groupBuckets in select type group. 123 * Updates groupBuckets in select type group.
110 * 124 *
111 - * @param deviceId target device id for group description 125 + * @param deviceId target device id to update the group
112 - * @param oldAppCookie group key for target group
113 * @param nodeList updated gateway node list for bucket action 126 * @param nodeList updated gateway node list for bucket action
114 - * @param nodeInsertion update type(add or remove) 127 + * @param isInsert update type(add or remove)
115 * @return result of process 128 * @return result of process
116 */ 129 */
117 - public boolean updateBucketToSelectGroupInVxlan(DeviceId deviceId, GroupKey oldAppCookie, 130 + public void updateGatewayGroupBuckets(DeviceId deviceId,
118 - List<GatewayNode> nodeList, boolean nodeInsertion) { 131 + List<GatewayNode> nodeList,
132 + boolean isInsert) {
119 List<GroupBucket> bucketList = generateBucketsForSelectGroup(deviceId, nodeList); 133 List<GroupBucket> bucketList = generateBucketsForSelectGroup(deviceId, nodeList);
120 - 134 + GroupKey groupKey = getGroupKey(deviceId);
121 - GroupKey newAppCookie = generateGroupKey(deviceId, nodeList); 135 + if (isInsert) {
122 - if (nodeInsertion) { 136 + groupService.addBucketsToGroup(
123 - groupService.addBucketsToGroup(deviceId, oldAppCookie, 137 + deviceId,
124 - new GroupBuckets(bucketList), newAppCookie, appId); 138 + groupKey,
139 + new GroupBuckets(bucketList),
140 + groupKey, appId);
125 } else { 141 } else {
126 - groupService.removeBucketsFromGroup(deviceId, oldAppCookie, 142 + groupService.removeBucketsFromGroup(
127 - new GroupBuckets(bucketList), newAppCookie, appId); 143 + deviceId,
144 + groupKey,
145 + new GroupBuckets(bucketList),
146 + groupKey, appId);
128 } 147 }
129 - Group group = groupService.getGroup(deviceId, newAppCookie);
130 - return group != null ? true : false;
131 } 148 }
132 149
133 private List<GroupBucket> generateBucketsForSelectGroup(DeviceId deviceId, List<GatewayNode> nodeList) { 150 private List<GroupBucket> generateBucketsForSelectGroup(DeviceId deviceId, List<GatewayNode> nodeList) {
...@@ -175,7 +192,7 @@ public class SelectGroupHandler { ...@@ -175,7 +192,7 @@ public class SelectGroupHandler {
175 */ 192 */
176 private PortNumber getTunnelPort(DeviceId deviceId) { 193 private PortNumber getTunnelPort(DeviceId deviceId) {
177 Port port = deviceService.getPorts(deviceId).stream() 194 Port port = deviceService.getPorts(deviceId).stream()
178 - .filter(p -> p.annotations().value(PORTNAME).equals(PORTNAME_PREFIX_TUNNEL)) 195 + .filter(p -> p.annotations().value(PORT_NAME).equals(PORTNAME_PREFIX_TUNNEL))
179 .findAny().orElse(null); 196 .findAny().orElse(null);
180 197
181 if (port == null) { 198 if (port == null) {
......