Prototyping mouse-over behaviour for path/traffic selection; needs re-work.
Change-Id: I27507e8129b790e56192077bfb56028f2ec56d90
diff --git a/web/gui/src/main/java/org/onlab/onos/gui/TopologyWebSocket.java b/web/gui/src/main/java/org/onlab/onos/gui/TopologyWebSocket.java
index 46bc930..9e2623f 100644
--- a/web/gui/src/main/java/org/onlab/onos/gui/TopologyWebSocket.java
+++ b/web/gui/src/main/java/org/onlab/onos/gui/TopologyWebSocket.java
@@ -91,7 +91,7 @@
private final IntentListener intentListener = new InternalIntentListener();
// Intents that are being monitored for the GUI
- private static Map<Intent, Long> intentsToMonitor = new ConcurrentHashMap<>();
+ private Map<Intent, Long> intentsToMonitor = new ConcurrentHashMap<>();
private long lastActive = System.currentTimeMillis();
private boolean listenersRemoved = false;
@@ -118,6 +118,8 @@
/**
* Indicates if this connection is idle.
+ *
+ * @return true if idle or closed
*/
synchronized boolean isIdle() {
boolean idle = (System.currentTimeMillis() - lastActive) > MAX_AGE_MS;
@@ -293,6 +295,10 @@
// Produces a set of intents that target all selected hosts or connect points.
private Set<Intent> getIntents(Set<Host> hosts, Set<ConnectPoint> edgePoints) {
Set<Intent> intents = new HashSet<>();
+ if (hosts.isEmpty()) {
+ return intents;
+ }
+
for (Intent intent : intentService.getIntents()) {
boolean isRelevant = false;
if (intent instanceof HostToHostIntent) {
@@ -454,6 +460,7 @@
ObjectNode payload = pathMessage(path, "host")
.put("intentId", intent.id().toString());
sendMessage(envelope("showPath", sid, payload));
+ sendMessage(trafficMessage(intentsToMonitor.keySet(), sid));
}
}
}
diff --git a/web/gui/src/main/webapp/topo2.js b/web/gui/src/main/webapp/topo2.js
index f93595f..dcde928 100644
--- a/web/gui/src/main/webapp/topo2.js
+++ b/web/gui/src/main/webapp/topo2.js
@@ -88,7 +88,7 @@
linkDistance: {
direct: 100,
optical: 120,
- hostLink: 5
+ hostLink: 3
},
linkStrength: {
direct: 1.0,
@@ -98,7 +98,7 @@
note_for_nodes: 'node.class is used to differentiate',
charge: {
device: -8000,
- host: -300
+ host: -5000
},
pad: 20,
translate: function() {
@@ -497,14 +497,16 @@
function showTraffic(data) {
fnTrace('showTraffic', data.payload.id);
- data.payload.paths.forEach(function () {
- var links = data.payload.links,
- s = [ data.event + "\n" + links.length ];
- links.forEach(function (d, i) {
- s.push(d);
- });
- network.view.alert(s.join('\n'));
+ var paths = data.payload.paths;
+ // Revert any links hilighted previously.
+ network.links.forEach(function (d) {
+ d.el.classed('showPath', false);
+ });
+
+ // Now hilight all links in the paths payload.
+ paths.forEach(function (d) {
+ var links = d.links;
links.forEach(function (d, i) {
var link = network.lookup[d];
if (link) {
@@ -559,10 +561,11 @@
return true;
}
- function requestTraffic() {
- if (nSel() > 0) {
+ function requestTraffic(hoverNode) {
+ if (nSel() > 0 || hoverNode) {
+ var nodes = hoverNode ? selectOrder.concat(hoverNode.id) : selectOrder;
sendMessage('requestTraffic', {
- ids: selectOrder
+ ids: nodes
});
} else {
userFeedback('Request-Traffic requires one or\n' +
@@ -582,11 +585,15 @@
}
}
- function cancelTraffic() {
- // FIXME: from where do we get the intent id(s) to send to the server?
- sendMessage('cancelTraffic', {
- ids: ["need_the_intent_id"]
- });
+ function cancelTraffic(hoverNode) {
+ if (hoverNode && selectOrder.length) {
+ requestTraffic();
+ } else {
+ // FIXME: from where do we get the intent id(s) to send to the server?
+ sendMessage('cancelTraffic', {
+ ids: ["need_the_intent_id"]
+ });
+ }
}
// request details for the selected element
@@ -943,7 +950,18 @@
opacity: 0
})
.call(network.drag)
- //.on('mouseover', function (d) {})
+ .on('mouseover', function (d) {
+ console.log(d);
+ if (d.class === 'host') {
+ requestTraffic(d);
+ }
+ })
+ .on('mouseout', function (d) {
+ console.log(d);
+ if (d.class === 'host') {
+ cancelTraffic(d);
+ }
+ })
//.on('mouseover', function (d) {})
.transition()
.attr('opacity', 1);