Thomas Vachuska

Fixing visuals for the SDN-IP demo.

Change-Id: I1d3020ab3787c1b560438e32fe4254edf6a640bd
{
"devices": [
{ "alias": "s1", "uri": "of:0000000000000001", "mac": "000000000001", "annotations": { "name": "DEN", "latitude": 39.739317, "longitude": -104.983791 }, "type": "SWITCH" },
{ "alias": "s2", "uri": "of:0000000000000002", "mac": "000000000002", "annotations": { "name": "ORD", "latitude": 41.880143, "longitude": -87.624257 }, "type": "SWITCH" },
{ "alias": "s3", "uri": "of:0000000000000003", "mac": "000000000003", "annotations": { "name": "ABQ", "latitude": 35.116541, "longitude": -106.604146 }, "type": "SWITCH" },
{ "alias": "s4", "uri": "of:0000000000000004", "mac": "000000000004", "annotations": { "name": "DFW", "latitude": 32.779501, "longitude": -96.801104 }, "type": "SWITCH" },
{ "alias": "s5", "uri": "of:0000000000000005", "mac": "000000000005", "annotations": { "name": "SEA", "latitude": 47.606126, "longitude": -122.332903 }, "type": "SWITCH" },
{ "alias": "s6", "uri": "of:0000000000000006", "mac": "000000000006", "annotations": { "name": "SFO", "latitude": 37.785286, "longitude": -122.406509 }, "type": "SWITCH" },
{ "alias": "s7", "uri": "of:0000000000000007", "mac": "000000000007", "annotations": { "name": "LAX", "latitude": 34.055604, "longitude": -118.248567 }, "type": "SWITCH" },
{ "alias": "s8", "uri": "of:0000000000000008", "mac": "000000000008", "annotations": { "name": "JFK", "latitude": 40.769487, "longitude": -73.972520 }, "type": "SWITCH" },
{ "alias": "s9", "uri": "of:0000000000000009", "mac": "000000000009", "annotations": { "name": "IAD", "latitude": 38.897676, "longitude": -77.036525 }, "type": "SWITCH" },
{ "alias": "s10", "uri": "of:0000000000000010", "mac": "000000000010", "annotations": { "name": "ATL", "latitude": 33.756298, "longitude": -84.388507 }, "type": "SWITCH" }
],
"hosts" : [
{ "mac": "00:00:00:00:00:01", "vlan": -1, "location": "of:0000000000000001/10", "ip": "0.0.0.0", "annotations": { "type": "bgpSpeaker" } },
{ "mac": "00:00:00:00:00:02", "vlan": -1, "location": "of:0000000000000002/10", "ip": "0.0.0.0", "annotations": { "type": "bgpSpeaker" } },
......
......@@ -56,6 +56,7 @@ import org.onlab.packet.IpAddress;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.DecimalFormat;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
......@@ -85,6 +86,15 @@ public abstract class TopologyViewMessages {
private static final ProviderId PID = new ProviderId("core", "org.onlab.onos.core", true);
private static final String COMPACT = "%s/%s-%s/%s";
private static final double KB = 1024;
private static final double MB = 1024 * KB;
private static final double GB = 1024 * MB;
private static final String GB_UNIT = "GB";
private static final String MB_UNIT = "MB";
private static final String KB_UNIT = "KB";
private static final String B_UNIT = "B";
protected final ServiceDirectory directory;
protected final ClusterService clusterService;
protected final DeviceService deviceService;
......@@ -424,14 +434,16 @@ public abstract class TopologyViewMessages {
ArrayNode labels = mapper.createArrayNode();
boolean hasTraffic = false;
for (Link link : links) {
linksNode.add(compactLinkString(link));
Load load = statService.load(link);
String label = "";
if (load.rate() > 0) {
hasTraffic = true;
label = load.latest() + " bytes";
if (isInfrastructureEgress(link)) {
linksNode.add(compactLinkString(link));
Load load = statService.load(link);
String label = "";
if (load.rate() > 0) {
hasTraffic = true;
label = format(load);
}
labels.add(label);
}
labels.add(label);
}
pathNode.put("class", hasTraffic ? type + " animated" : type);
pathNode.put("traffic", hasTraffic);
......@@ -441,6 +453,32 @@ public abstract class TopologyViewMessages {
}
}
// Poor-mans formatting to get the labels with byte counts looking nice.
private String format(Load load) {
long bytes = load.latest();
String unit;
double value;
if (bytes > GB) {
value = bytes / GB;
unit = GB_UNIT;
} else if (bytes > MB) {
value = bytes / MB;
unit = MB_UNIT;
} else if (bytes > KB) {
value = bytes / KB;
unit = KB_UNIT;
} else {
value = bytes;
unit = B_UNIT;
}
DecimalFormat format = new DecimalFormat("#,###.##");
return format.format(value) + " " + unit;
}
private boolean isInfrastructureEgress(Link link) {
return link.src().elementId() instanceof DeviceId;
}
// Produces compact string representation of a link.
private static String compactLinkString(Link link) {
return String.format(COMPACT, link.src().elementId(), link.src().port(),
......
......@@ -143,7 +143,7 @@ svg .node.host circle {
}
#topo svg .link.animated {
stroke: #f11;
stroke-width: 8px;
stroke-width: 6px;
stroke-dasharray: 8 8
}
......@@ -162,15 +162,16 @@ svg .node.host circle {
}
#topo svg .linkLabel rect {
fill: #eef;
stroke: blue;
stroke-width: 0.3;
stroke: #999;
stroke-width: 1.2px;
fill: #eee;
stroke: none;
}
#topo svg .linkLabel text {
text-anchor: middle;
fill: #a13d11;
stroke: none;
font-size: 8pt;
stroke: #777;
stroke-width: 0.1px;
font-size: 9pt;
}
/* Fly-in details pane */
......