Fixed to add gateway node from ICMP handler also

And made the gateway store or group update synchronized

Change-Id: I10fc391e9059772e5da8322997a994db26a096b3
diff --git a/apps/openstacknetworking/routing/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackFloatingIpManager.java b/apps/openstacknetworking/routing/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackFloatingIpManager.java
index ba60fe8..236d04d 100644
--- a/apps/openstacknetworking/routing/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackFloatingIpManager.java
+++ b/apps/openstacknetworking/routing/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackFloatingIpManager.java
@@ -309,13 +309,15 @@
                 case COMPLETE:
                     if (node.type() == GATEWAY) {
                         log.info("GATEWAY node {} detected", node.hostname());
-                        GatewayNode gnode = GatewayNode.builder()
-                                .gatewayDeviceId(node.intBridge())
-                                .dataIpAddress(node.dataIp().getIp4Address())
-                                .uplinkIntf(node.externalPortName().get())
-                                .build();
-                        gatewayService.addGatewayNode(gnode);
-                        eventExecutor.execute(OpenstackFloatingIpManager.this::reloadFloatingIpRules);
+                        eventExecutor.execute(() -> {
+                            GatewayNode gnode = GatewayNode.builder()
+                                    .gatewayDeviceId(node.intBridge())
+                                    .dataIpAddress(node.dataIp().getIp4Address())
+                                    .uplinkIntf(node.externalPortName().get())
+                                    .build();
+                            gatewayService.addGatewayNode(gnode);
+                            reloadFloatingIpRules();
+                        });
                     }
                     break;
                 case INIT:
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 f46a94b..007efb6 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
@@ -49,6 +49,7 @@
 import org.onosproject.openstacknode.OpenstackNodeEvent;
 import org.onosproject.openstacknode.OpenstackNodeListener;
 import org.onosproject.openstacknode.OpenstackNodeService;
+import org.onosproject.scalablegateway.api.GatewayNode;
 import org.onosproject.scalablegateway.api.ScalableGatewayService;
 import org.slf4j.Logger;
 
@@ -322,7 +323,15 @@
                 case COMPLETE:
                     if (node.type() == GATEWAY) {
                         log.info("GATEWAY node {} detected", node.hostname());
-                        eventExecutor.execute(() -> requestPacket(appId));
+                        eventExecutor.execute(() -> {
+                            GatewayNode gnode = GatewayNode.builder()
+                                    .gatewayDeviceId(node.intBridge())
+                                    .dataIpAddress(node.dataIp().getIp4Address())
+                                    .uplinkIntf(node.externalPortName().get())
+                                    .build();
+                            gatewayService.addGatewayNode(gnode);
+                            requestPacket(appId);
+                        });
                     }
                     break;
                 case INIT:
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 09b4b8a..970a331 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
@@ -481,15 +481,17 @@
             switch (event.type()) {
                 case COMPLETE:
                     log.info("COMPLETE node {} detected", node.hostname());
-                    if (node.type() == GATEWAY) {
-                        GatewayNode gnode = GatewayNode.builder()
-                                .gatewayDeviceId(node.intBridge())
-                                .dataIpAddress(node.dataIp().getIp4Address())
-                                .uplinkIntf(node.externalPortName().get())
-                                .build();
-                        gatewayService.addGatewayNode(gnode);
-                    }
-                    eventExecutor.execute(OpenstackRoutingManager.this::reloadRoutingRules);
+                    eventExecutor.execute(() -> {
+                        if (node.type() == GATEWAY) {
+                            GatewayNode gnode = GatewayNode.builder()
+                                    .gatewayDeviceId(node.intBridge())
+                                    .dataIpAddress(node.dataIp().getIp4Address())
+                                    .uplinkIntf(node.externalPortName().get())
+                                    .build();
+                            gatewayService.addGatewayNode(gnode);
+                        }
+                        reloadRoutingRules();
+                    });
                     break;
                 case INIT:
                 case DEVICE_CREATED:
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 5e1d2b0..d7cfc06 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
@@ -208,7 +208,7 @@
     }
 
     @Override
-    public boolean addGatewayNode(GatewayNode gatewayNode) {
+    public synchronized boolean addGatewayNode(GatewayNode gatewayNode) {
         Versioned<GatewayNode> existingNode = gatewayNodeMap.putIfAbsent(
                 gatewayNode.getGatewayDeviceId(), gatewayNode);
         if (existingNode == null) {
@@ -221,7 +221,7 @@
     }
 
     @Override
-    public boolean deleteGatewayNode(GatewayNode gatewayNode) {
+    public synchronized boolean deleteGatewayNode(GatewayNode gatewayNode) {
         boolean result = gatewayNodeMap.remove(gatewayNode.getGatewayDeviceId(), gatewayNode);
         if (result) {
             updateGatewayGroup(gatewayNode, false);