use of org.onosproject.net.ElementId in project onos by opennetworkinglab.
the class DefaultTapiResolver method getNodeRef.
@Override
public TapiNodeRef getNodeRef(ElementId deviceId) throws NoSuchElementException {
updateCache();
TapiNodeRef ret = null;
try {
ret = tapiNodeRefList.stream().filter(node -> node.getDeviceId() != null && node.getDeviceId().equals(deviceId)).findFirst().get();
} catch (NoSuchElementException e) {
log.error("Node not found associated with {}", deviceId);
throw e;
}
return ret;
}
use of org.onosproject.net.ElementId in project onos by opennetworkinglab.
the class UiLinkId method canonicalizeIdentifier.
private static UiLinkId canonicalizeIdentifier(ConnectPoint src, ConnectPoint dst) {
if (src == null || dst == null) {
throw new NullPointerException("null src or dst connect point (illegal for UiLinkId)");
}
ElementId srcId = src.elementId();
ElementId dstId = dst.elementId();
// canonicalize
int comp = srcId.toString().compareTo(dstId.toString());
return comp <= 0 ? new UiLinkId(srcId, src.port(), dstId, dst.port()) : new UiLinkId(dstId, dst.port(), srcId, src.port());
}
use of org.onosproject.net.ElementId in project onos by opennetworkinglab.
the class MockLinkService method addLink.
public void addLink(String device, long port, String device2, long port2) {
ElementId d1;
if (device.charAt(0) == 'H') {
device = device.substring(1, device.length());
d1 = HostId.hostId(device);
} else {
d1 = DeviceId.deviceId(device);
}
ElementId d2;
if (device2.charAt(0) == 'H') {
d2 = HostId.hostId(device2.substring(1, device2.length()));
} else {
d2 = DeviceId.deviceId(device2);
}
ConnectPoint src = new ConnectPoint(d1, PortNumber.portNumber(port));
ConnectPoint dst = new ConnectPoint(d2, PortNumber.portNumber(port2));
Link curLink;
curLink = DefaultLink.builder().src(src).dst(dst).state(ACTIVE).build();
links.add(curLink);
if (d1 instanceof DeviceId && d2 instanceof DeviceId) {
TopologyVertex v1 = () -> (DeviceId) d1, v2 = () -> (DeviceId) d2;
createdGraph.addVertex(v1);
createdGraph.addVertex(v2);
createdGraph.addEdge(new TopologyEdge() {
@Override
public Link link() {
return curLink;
}
@Override
public TopologyVertex src() {
return v1;
}
@Override
public TopologyVertex dst() {
return v2;
}
});
}
}
use of org.onosproject.net.ElementId in project onos by opennetworkinglab.
the class UiLinkId method directionOf.
/**
* Returns the direction of the given link, or null if this link ID does
* not correspond to the given link.
*
* @param link the link to examine
* @return corresponding direction
*/
Direction directionOf(Link link) {
ConnectPoint src = link.src();
ElementId srcId = src.elementId();
return elementA.equals(srcId) ? Direction.A_TO_B : elementB.equals(srcId) ? Direction.B_TO_A : null;
}
use of org.onosproject.net.ElementId in project onos by opennetworkinglab.
the class ConnectPointCodec method decode.
@Override
public ConnectPoint decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
ElementId elementId;
if (json.has(ELEMENT_DEVICE)) {
elementId = DeviceId.deviceId(json.get(ELEMENT_DEVICE).asText());
} else if (json.has(ELEMENT_HOST)) {
elementId = HostId.hostId(json.get(ELEMENT_HOST).asText());
} else {
// invalid JSON
return null;
}
PortNumber portNumber = portNumber(json.get(PORT).asText());
return new ConnectPoint(elementId, portNumber);
}
Aggregations