ONOS-6258: UiTopo2Overlay et al.
- Added Topo2TrafficMessageHandler
- Wired topo2 traffic overlay into topo2 view

Change-Id: I2b67af6abc10f737b8d3183d219d8c651bf57e31
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java b/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java
index 6bab13e..5e36357 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java
@@ -56,6 +56,7 @@
 import org.onosproject.ui.UiTopoOverlayFactory;
 import org.onosproject.ui.UiView;
 import org.onosproject.ui.UiViewHidden;
+import org.onosproject.ui.impl.topo.Topo2TrafficMessageHandler;
 import org.onosproject.ui.impl.topo.Topo2ViewMessageHandler;
 import org.onosproject.ui.impl.topo.Traffic2Overlay;
 import org.slf4j.Logger;
@@ -151,6 +152,7 @@
                         new UserPreferencesMessageHandler(),
                         new TopologyViewMessageHandler(),
                         new Topo2ViewMessageHandler(),
+                        new Topo2TrafficMessageHandler(),
                         new MapSelectorMessageHandler(),
                         new DeviceViewMessageHandler(),
                         new LinkViewMessageHandler(),
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/UiWebSocket.java b/web/gui/src/main/java/org/onosproject/ui/impl/UiWebSocket.java
index c302c6b..2179f42 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/UiWebSocket.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/UiWebSocket.java
@@ -296,6 +296,10 @@
             overlayCache.destroy();
             overlayCache = null;
         }
+        if (overlay2Cache != null) {
+            overlay2Cache.destroy();
+            overlay2Cache = null;
+        }
     }
 
     // Sends initial information (username and cluster member information)
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/Topo2TrafficMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/Topo2TrafficMessageHandler.java
new file mode 100644
index 0000000..8a6ec8b
--- /dev/null
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/Topo2TrafficMessageHandler.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.onosproject.ui.impl.topo;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.ImmutableSet;
+import org.onlab.osgi.ServiceDirectory;
+import org.onosproject.ui.RequestHandler;
+import org.onosproject.ui.UiConnection;
+import org.onosproject.ui.UiMessageHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+
+/**
+ * Server-side component to handle messages pertaining to topo-2 traffic.
+ */
+public class Topo2TrafficMessageHandler extends UiMessageHandler {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    // === Inbound event identifiers
+    private static final String REQUEST_ALL_TRAFFIC = "topo2RequestAllTraffic";
+    private static final String CANCEL_TRAFFIC = "topo2CancelTraffic";
+
+    // === Outbound event identifiers
+    private static final String HIGHLIGHTS = "topo2Highlights";
+
+//    private UiTopoSession topoSession;
+//    private Topo2Jsonifier t2json;
+
+    @Override
+    public void init(UiConnection connection, ServiceDirectory directory) {
+        super.init(connection, directory);
+
+        // get the topo session from the UiWebSocket
+//        topoSession = ((UiWebSocket) connection).topoSession();
+//        t2json = new Topo2Jsonifier(directory, connection.userName());
+
+    }
+
+    @Override
+    protected Collection<RequestHandler> createRequestHandlers() {
+        return ImmutableSet.of(
+                new Topo2AllTraffic(),
+                new Topo2CancelTraffic()
+        );
+    }
+
+    // ==================================================================
+
+    private final class Topo2AllTraffic extends RequestHandler {
+        private Topo2AllTraffic() {
+            super(REQUEST_ALL_TRAFFIC);
+        }
+
+        @Override
+        public void process(ObjectNode payload) {
+            String mode = string(payload, "trafficType");
+            log.debug("SHOW TRAFFIC: " + mode);
+            switch (mode) {
+                case "flowStatsBytes":
+                    // TODO: invoke traffic monitor for flow stats / bytes
+                    break;
+
+                case "portStatsBitSec":
+                    // TODO: invoke traffic monitor for port stats / bps
+                    break;
+
+                case "portStatsPktSec":
+                    // TODO: invoke traffic monitor for port stats / pps
+                    break;
+
+                default:
+                    log.warn("Unknown traffic monitor type: " + mode);
+                    break;
+            }
+        }
+    }
+
+    private final class Topo2CancelTraffic extends RequestHandler {
+        private Topo2CancelTraffic() {
+            super(CANCEL_TRAFFIC);
+        }
+
+        @Override
+        public void process(ObjectNode payload) {
+            log.debug("CANCEL TRAFFIC");
+            // TODO: tell traffic monitor to quit monitoring traffic
+        }
+    }
+}
+
+