Hyunsun Moon
Committed by Gerrit Code Review

Fix to update gateway group only if new gateway is added

Also implemented equals, hashCode, and toString for GatewayNode.

Change-Id: I4c487cafa263833701c5790b2057c1d9c23e33bf
...@@ -15,9 +15,12 @@ ...@@ -15,9 +15,12 @@
15 */ 15 */
16 package org.onosproject.scalablegateway.api; 16 package org.onosproject.scalablegateway.api;
17 17
18 +import com.google.common.base.MoreObjects;
18 import org.onlab.packet.Ip4Address; 19 import org.onlab.packet.Ip4Address;
19 import org.onosproject.net.DeviceId; 20 import org.onosproject.net.DeviceId;
20 21
22 +import java.util.Objects;
23 +
21 import static com.google.common.base.Preconditions.checkNotNull; 24 import static com.google.common.base.Preconditions.checkNotNull;
22 25
23 /** 26 /**
...@@ -62,6 +65,40 @@ public final class GatewayNode { ...@@ -62,6 +65,40 @@ public final class GatewayNode {
62 return dataIpAddress; 65 return dataIpAddress;
63 } 66 }
64 67
68 + @Override
69 + public boolean equals(Object obj) {
70 + if (this == obj) {
71 + return true;
72 + }
73 +
74 + if (obj instanceof GatewayNode) {
75 + GatewayNode that = (GatewayNode) obj;
76 + if (Objects.equals(gatewayDeviceId, that.gatewayDeviceId) &&
77 + Objects.equals(gatewayExternalInterfaceName,
78 + that.gatewayExternalInterfaceName) &&
79 + Objects.equals(dataIpAddress, that.dataIpAddress)) {
80 + return true;
81 + }
82 + }
83 + return false;
84 + }
85 +
86 + @Override
87 + public int hashCode() {
88 + return Objects.hash(gatewayDeviceId,
89 + gatewayExternalInterfaceName,
90 + dataIpAddress);
91 + }
92 +
93 + @Override
94 + public String toString() {
95 + return MoreObjects.toStringHelper(getClass())
96 + .add("deviceId", gatewayDeviceId)
97 + .add("externalPort", gatewayExternalInterfaceName)
98 + .add("dataIp", dataIpAddress)
99 + .toString();
100 + }
101 +
65 /** 102 /**
66 * Returns GatewayNode builder object. 103 * Returns GatewayNode builder object.
67 * 104 *
......
...@@ -203,9 +203,15 @@ public class ScalableGatewayManager implements ScalableGatewayService { ...@@ -203,9 +203,15 @@ public class ScalableGatewayManager implements ScalableGatewayService {
203 203
204 @Override 204 @Override
205 public boolean addGatewayNode(GatewayNode gatewayNode) { 205 public boolean addGatewayNode(GatewayNode gatewayNode) {
206 - gatewayNodeMap.putIfAbsent(gatewayNode.getGatewayDeviceId(), gatewayNode); 206 + Versioned<GatewayNode> existingNode = gatewayNodeMap.putIfAbsent(
207 + gatewayNode.getGatewayDeviceId(), gatewayNode);
208 + if (existingNode == null) {
207 updateGatewayLoadBalance(gatewayNode, true); 209 updateGatewayLoadBalance(gatewayNode, true);
210 + log.info("Added {} to gateway pool", gatewayNode);
208 return true; 211 return true;
212 + } else {
213 + return false;
214 + }
209 } 215 }
210 216
211 @Override 217 @Override
......