mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-16 01:41:26 +02:00
Added support for grid coordinates in the legacy topology view.
Change-Id: I48533f24eded919673af92a59cc5e2edefef46b3
This commit is contained in:
parent
3b9644f6c1
commit
c67a9912cc
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.onosproject.net.config.basics;
|
package org.onosproject.net.config.basics;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic configuration for network elements, e.g. devices, hosts. Such elements
|
* Basic configuration for network elements, e.g. devices, hosts. Such elements
|
||||||
* can have a friendly name, geo-coordinates (or grid-coordinates),
|
* can have a friendly name, geo-coordinates (or grid-coordinates),
|
||||||
@ -202,16 +204,12 @@ public abstract class BasicElementConfig<S> extends AllowedEntityConfig<S> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the grid coordinates (gridY and gridX) are set on
|
* Returns true if the grid coordinates (gridY and gridX) are set on
|
||||||
* this element; false otherwise.
|
* this element, i.e. if locType is set to 'grid'; false otherwise.
|
||||||
* <p>
|
|
||||||
* It is assumed that elements will not be placed at {@code (0,0)}.
|
|
||||||
* If you really need to position the element there, consider setting the
|
|
||||||
* coordinates to something like {@code (0.000001, 0.000001)} instead.
|
|
||||||
*
|
*
|
||||||
* @return true if grid coordinates are set; false otherwise.
|
* @return true if grid coordinates are set; false otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean gridCoordsSet() {
|
public boolean gridCoordsSet() {
|
||||||
return !doubleIsZero(gridY()) || !doubleIsZero(gridX());
|
return Objects.equals(locType(), LOC_TYPE_GRID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -117,7 +117,7 @@ public class BasicElementConfigTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void someGridCoords() {
|
public void someGridCoords() {
|
||||||
cfg.gridX(35.0).gridY(49.7);
|
cfg.gridX(35.0).gridY(49.7).locType(GRID);
|
||||||
print(cfg);
|
print(cfg);
|
||||||
assertTrue("grid at origin?", cfg.gridCoordsSet());
|
assertTrue("grid at origin?", cfg.gridCoordsSet());
|
||||||
assertEquals("gridx", 35.0, cfg.gridX(), ZERO_THRESHOLD);
|
assertEquals("gridx", 35.0, cfg.gridX(), ZERO_THRESHOLD);
|
||||||
|
@ -61,15 +61,22 @@ function sim {
|
|||||||
echo "$@" >> $CMDS
|
echo "$@" >> $CMDS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function y {
|
||||||
|
let p="${3:-300} * ($1 - 1) - (${3:-300} * ($2 - 1)) / 2"
|
||||||
|
echo $p
|
||||||
|
}
|
||||||
|
|
||||||
# Create spines
|
# Create spines
|
||||||
for spine in $(seq 1 $spines); do
|
for spine in $(seq 1 $spines); do
|
||||||
sim "null-create-device switch Spine-${spine} ${spinePorts}"
|
sim "null-create-device switch Spine-${spine} ${spinePorts} 0 $(y $spine $spines) grid"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Create 2 leaf pairs with dual links to the spines and a link between the pair
|
# Create 2 leaf pairs with dual links to the spines and a link between the pair
|
||||||
for pair in $serviceLeafGroups; do
|
for pair in $serviceLeafGroups; do
|
||||||
sim "null-create-device switch Leaf-${pair}1 ${leafPorts}"
|
[ $pair = A ] && l1=1 || l1=3
|
||||||
sim "null-create-device switch Leaf-${pair}2 ${leafPorts}"
|
[ $pair = A ] && l2=2 || l2=4
|
||||||
|
sim "null-create-device switch Leaf-${pair}1 ${leafPorts} -200 $(y $l1 4) grid"
|
||||||
|
sim "null-create-device switch Leaf-${pair}2 ${leafPorts} -200 $(y $l2 4) grid"
|
||||||
sim "null-create-link direct Leaf-${pair}1 Leaf-${pair}2"
|
sim "null-create-link direct Leaf-${pair}1 Leaf-${pair}2"
|
||||||
|
|
||||||
for spine in $(seq 1 $spines); do
|
for spine in $(seq 1 $spines); do
|
||||||
@ -88,7 +95,7 @@ done
|
|||||||
|
|
||||||
# Create single access leafs with dual links to the spines
|
# Create single access leafs with dual links to the spines
|
||||||
for access in $(seq $accessLeaves); do
|
for access in $(seq $accessLeaves); do
|
||||||
sim "null-create-device switch Access-${access} ${accessPorts}"
|
sim "null-create-device switch Access-${access} ${accessPorts} 200 $(y $access $accessLeaves) grid"
|
||||||
|
|
||||||
for spine in $(seq 1 $spines); do
|
for spine in $(seq 1 $spines); do
|
||||||
for link in $(seq 1 $spineLinks); do
|
for link in $(seq 1 $spineLinks); do
|
||||||
|
@ -308,6 +308,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler {
|
|||||||
payload.set("labels", labels("", name, device.id().toString()));
|
payload.set("labels", labels("", name, device.id().toString()));
|
||||||
payload.set("props", props(device.annotations()));
|
payload.set("props", props(device.annotations()));
|
||||||
addGeoLocation(device, payload);
|
addGeoLocation(device, payload);
|
||||||
|
addGridLocation(device, payload);
|
||||||
addMetaUi(device.id().toString(), payload);
|
addMetaUi(device.id().toString(), payload);
|
||||||
|
|
||||||
String type = DEVICE_EVENT.get(event.type());
|
String type = DEVICE_EVENT.get(event.type());
|
||||||
@ -354,6 +355,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler {
|
|||||||
payload.set("labels", labels(nameForHost(host), ip, host.mac().toString(), ""));
|
payload.set("labels", labels(nameForHost(host), ip, host.mac().toString(), ""));
|
||||||
payload.set("props", props(host.annotations()));
|
payload.set("props", props(host.annotations()));
|
||||||
addGeoLocation(host, payload);
|
addGeoLocation(host, payload);
|
||||||
|
addGridLocation(host, payload);
|
||||||
addMetaUi(host.id().toString(), payload);
|
addMetaUi(host.id().toString(), payload);
|
||||||
|
|
||||||
String type = HOST_EVENT.get(event.type());
|
String type = HOST_EVENT.get(event.type());
|
||||||
@ -428,6 +430,30 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adds a grid location JSON to the specified payload object.
|
||||||
|
private void addGridLocation(Annotated annotated, ObjectNode payload) {
|
||||||
|
Annotations annotations = annotated.annotations();
|
||||||
|
if (annotations == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String xs = annotations.value(AnnotationKeys.GRID_X);
|
||||||
|
String ys = annotations.value(AnnotationKeys.GRID_Y);
|
||||||
|
if (xs != null && ys != null) {
|
||||||
|
try {
|
||||||
|
double x = Double.parseDouble(xs);
|
||||||
|
double y = Double.parseDouble(ys);
|
||||||
|
ObjectNode loc = objectNode()
|
||||||
|
.put("locType", "grid")
|
||||||
|
.put("latOrY", y)
|
||||||
|
.put("longOrX", x);
|
||||||
|
payload.set("location", loc);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
log.warn("Invalid grid data: x={}, y={}", xs, ys);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Updates meta UI information for the specified object.
|
// Updates meta UI information for the specified object.
|
||||||
protected void updateMetaUi(ObjectNode payload) {
|
protected void updateMetaUi(ObjectNode payload) {
|
||||||
metaUi.put(JsonUtils.string(payload, "id"),
|
metaUi.put(JsonUtils.string(payload, "id"),
|
||||||
|
@ -55,6 +55,20 @@
|
|||||||
return p ? p.invert(coord) : [0, 0];
|
return p ? p.invert(coord) : [0, 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function coordFromXY(loc) {
|
||||||
|
var bgWidth = 1000,
|
||||||
|
bgHeight = 1000;
|
||||||
|
|
||||||
|
var scale = 1000 / bgWidth,
|
||||||
|
yOffset = (1000 - (bgHeight * scale)) / 2;
|
||||||
|
|
||||||
|
// 1000 is a hardcoded HTML value of the SVG element (topo2.html)
|
||||||
|
var x = scale * loc.longOrX,
|
||||||
|
y = (scale * loc.latOrY) + yOffset;
|
||||||
|
|
||||||
|
return [x, y];
|
||||||
|
}
|
||||||
|
|
||||||
function positionNode(node, forUpdate) {
|
function positionNode(node, forUpdate) {
|
||||||
var meta = node.metaUi,
|
var meta = node.metaUi,
|
||||||
x = meta && meta.x,
|
x = meta && meta.x,
|
||||||
@ -114,8 +128,8 @@
|
|||||||
var loc = node.location,
|
var loc = node.location,
|
||||||
coord;
|
coord;
|
||||||
|
|
||||||
if (loc && loc.locType === 'geo') {
|
if (loc) {
|
||||||
coord = coordFromLngLat(loc);
|
coord = loc.locType === 'geo' ? coordFromLngLat(loc) : coordFromXY(loc);
|
||||||
node.fixed = true;
|
node.fixed = true;
|
||||||
node.px = node.x = coord[0];
|
node.px = node.x = coord[0];
|
||||||
node.py = node.y = coord[1];
|
node.py = node.y = coord[1];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user