Thomas Vachuska

Added GUI integration for device & host properties.

Fixed cell files to remove ONOS_CELL definition within; this is defined externally based on the cell itself.
# Local VirtualBox-based single ONOS instance & ONOS mininet box
export ONOS_CELL="cbench"
export ONOS_NIC=192.168.56.*
export OC1="192.168.56.103"
export OCN="192.168.56.103"
......
# Local VirtualBox-based ONOS instances 1,2 & ONOS mininet box
export ONOS_CELL="local"
export ONOS_NIC=192.168.56.*
export OC1="192.168.56.101"
export OC2="192.168.56.102"
......
# ProxMox-based cell of ONOS instance; no mininet-box
export ONOS_CELL="office"
export ONOS_NIC="10.1.10.*"
export OC1="10.1.10.223"
export OCI="${OC1}"
......
# ProxMox-based cell of ONOS instances 1,2 & ONOS mininet box
export ONOS_CELL="prox"
export ONOS_NIC="10.1.9.*"
export OC1="10.1.9.94"
export OC2="10.1.9.82"
......
# Local VirtualBox-based single ONOS instance & ONOS mininet box
export ONOS_CELL="single"
export ONOS_NIC=192.168.56.*
export OC1="192.168.56.101"
export OCN="192.168.56.103"
......
# Local VirtualBox-based ONOS instances 1,2,3 & ONOS mininet box
export ONOS_CELL="triple"
export ONOS_NIC=192.168.56.*
export OC1="192.168.56.101"
export OC2="192.168.56.102"
......
......@@ -18,9 +18,12 @@ package org.onlab.onos.gui;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onlab.onos.net.Annotations;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.Device;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Host;
import org.onlab.onos.net.HostId;
import org.onlab.onos.net.HostLocation;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.device.DeviceService;
......@@ -35,6 +38,7 @@ import org.onlab.packet.MacAddress;
import org.onlab.rest.BaseResource;
import javax.ws.rs.GET;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import java.util.HashMap;
......@@ -43,12 +47,17 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import static org.onlab.onos.net.DeviceId.deviceId;
import static org.onlab.onos.net.HostId.hostId;
/**
* Topology viewer resource.
*/
@javax.ws.rs.Path("topology")
public class TopologyResource extends BaseResource {
private static final String HOST_SEP = "/";
@javax.ws.rs.Path("/graph")
@GET
@Produces("application/json")
......@@ -70,6 +79,60 @@ public class TopologyResource extends BaseResource {
return Response.ok(rootNode.toString()).build();
}
@javax.ws.rs.Path("/graph/{id}")
@GET
@Produces("application/json")
public Response details(@PathParam("id") String id) {
if (id.contains(HOST_SEP)) {
return hostDetails(hostId(id));
}
return deviceDetails(deviceId(id));
}
// Returns device details response.
private Response deviceDetails(DeviceId deviceId) {
DeviceService deviceService = get(DeviceService.class);
Device device = deviceService.getDevice(deviceId);
Annotations annot = device.annotations();
ObjectNode r = json(deviceId.toString(),
new Prop("Name", annot.value("name")),
new Prop("Vendor", device.manufacturer()),
new Prop("H/W Version", device.hwVersion()),
new Prop("S/W Version", device.swVersion()),
new Prop("S/W Version", device.serialNumber()),
new Prop("Latitude", annot.value("latitude")),
new Prop("Longitude", annot.value("longitude")));
return Response.ok(r.toString()).build();
}
// Returns host details response.
private Response hostDetails(HostId hostId) {
HostService hostService = get(HostService.class);
Host host = hostService.getHost(hostId);
Annotations annot = host.annotations();
ObjectNode r = json(hostId.toString(),
new Prop("MAC", host.mac().toString()),
new Prop("IP", host.ipAddresses().toString()),
new Prop("Latitude", annot.value("latitude")),
new Prop("Longitude", annot.value("longitude")));
return Response.ok(r.toString()).build();
}
// Produces JSON property details.
private ObjectNode json(String id, Prop... props) {
ObjectMapper mapper = new ObjectMapper();
ObjectNode result = mapper.createObjectNode().put("id", id);
ObjectNode pnode = mapper.createObjectNode();
ArrayNode porder = mapper.createArrayNode();
for (Prop p : props) {
porder.add(p.key);
pnode.put(p.key, p.value);
}
result.set("propOrder", porder);
result.set("props", pnode);
return result;
}
// Encodes all infrastructure devices.
private ArrayNode getDevices(ObjectMapper mapper, DeviceService deviceService,
TopologyGraph graph) {
......@@ -209,4 +272,14 @@ public class TopologyResource extends BaseResource {
return cp.elementId().toString();
}
// Auxiliary key/value carrier.
private final class Prop {
private final String key;
private final String value;
private Prop(String key, String value) {
this.key = key;
this.value = value;
}
}
}
......
......@@ -38,6 +38,7 @@
collisionPrevention: true
},
XjsonUrl: 'rs/topology/graph',
XjsonPrefix: '',
jsonUrl: 'json/network.json',
jsonPrefix: 'json/',
iconUrl: {
......@@ -889,8 +890,11 @@
}
function detailUrl(id) {
var safeId = id.replace(/[^a-z0-9]/gi, '_');
return config.jsonPrefix + safeId + '.json';
if (config.jsonPrefix) {
var safeId = id.replace(/[^a-z0-9]/gi, '_');
return config.jsonPrefix + safeId + '.json';
}
return config.jsonUrl + '/' + encodeURIComponent(id);
}
function flyinPane(obj) {
......