use of org.onosproject.net.link.LinkService in project onos by opennetworkinglab.
the class OpticalIntentsWebResource method decode.
private Intent decode(ObjectNode json) {
JsonNode ingressJson = json.get(INGRESS_POINT);
if (!ingressJson.isObject()) {
throw new IllegalArgumentException(JSON_INVALID);
}
ConnectPoint ingress = codec(ConnectPoint.class).decode((ObjectNode) ingressJson, this);
JsonNode egressJson = json.get(EGRESS_POINT);
if (!egressJson.isObject()) {
throw new IllegalArgumentException(JSON_INVALID);
}
ConnectPoint egress = codec(ConnectPoint.class).decode((ObjectNode) egressJson, this);
JsonNode bidirectionalJson = json.get(BIDIRECTIONAL);
boolean bidirectional = bidirectionalJson != null ? bidirectionalJson.asBoolean() : false;
JsonNode signalJson = json.get(SIGNAL);
OchSignal signal = null;
if (signalJson != null) {
if (!signalJson.isObject()) {
throw new IllegalArgumentException(JSON_INVALID);
} else {
signal = OchSignalCodec.decode((ObjectNode) signalJson);
}
}
String appIdString = nullIsIllegal(json.get(APP_ID), APP_ID + MISSING_MEMBER_MESSAGE).asText();
CoreService service = getService(CoreService.class);
ApplicationId appId = nullIsNotFound(service.getAppId(appIdString), E_APP_ID_NOT_FOUND);
Key key = null;
DeviceService deviceService = get(DeviceService.class);
JsonNode suggestedPathJson = json.get(SUGGESTEDPATH);
DefaultPath suggestedPath = null;
LinkService linkService = get(LinkService.class);
if (suggestedPathJson != null) {
if (!suggestedPathJson.isObject()) {
throw new IllegalArgumentException(JSON_INVALID);
} else {
ArrayNode linksJson = nullIsIllegal((ArrayNode) suggestedPathJson.get("links"), "Suggested path specified without links");
List<Link> listLinks = new ArrayList<>();
for (JsonNode node : linksJson) {
String srcString = node.get("src").asText();
String dstString = node.get("dst").asText();
ConnectPoint srcConnectPoint = ConnectPoint.fromString(srcString);
ConnectPoint dstConnectPoint = ConnectPoint.fromString(dstString);
Link link = linkService.getLink(srcConnectPoint, dstConnectPoint);
if (link == null) {
throw new IllegalArgumentException("Not existing link in the suggested path");
}
listLinks.add(link);
}
if ((!listLinks.get(0).src().deviceId().equals(ingress.deviceId())) || (!listLinks.get(0).src().port().equals(ingress.port())) || (!listLinks.get(listLinks.size() - 1).dst().deviceId().equals(egress.deviceId())) || (!listLinks.get(listLinks.size() - 1).dst().port().equals(egress.port()))) {
throw new IllegalArgumentException("Suggested path not compatible with ingress or egress connect points");
}
if (!isPathContiguous(listLinks)) {
throw new IllegalArgumentException("Links specified in the suggested path are not contiguous");
}
suggestedPath = new DefaultPath(PROVIDER_ID, listLinks, new ScalarWeight(1));
log.debug("OpticalIntent along suggestedPath {}", suggestedPath);
}
}
return createExplicitOpticalIntent(ingress, egress, deviceService, key, appId, bidirectional, signal, suggestedPath);
}
use of org.onosproject.net.link.LinkService in project trellis-control by opennetworkinglab.
the class LinkHandler method lastUplink.
/**
* Returns true if given link was the last active uplink from src-device of
* link. An uplink is defined as a unidirectional link with src as
* edgeRouter and dst as non-edgeRouter.
*
* @param link
* @return true if given link was the last uplink from the src device
*/
private boolean lastUplink(Link link) {
DeviceConfiguration devConfig = srManager.deviceConfiguration;
try {
if (!devConfig.isEdgeDevice(link.src().deviceId()) || devConfig.isEdgeDevice(link.dst().deviceId())) {
return false;
}
// note that using linkservice here would cause race conditions as
// more links can show up while the app is still processing the first one
Set<Link> devLinks = seenLinks.entrySet().stream().filter(entry -> entry.getKey().src().deviceId().equals(link.src().deviceId())).filter(entry -> entry.getValue()).filter(entry -> !entry.getKey().equals(link)).map(entry -> entry.getKey()).collect(Collectors.toSet());
for (Link l : devLinks) {
if (devConfig.isEdgeDevice(l.dst().deviceId())) {
continue;
}
log.debug("Found another active uplink {}", l);
return false;
}
log.debug("No active uplink found");
return true;
} catch (DeviceConfigNotFoundException e) {
log.warn("Unable to determine if link was the last uplink" + e.getMessage());
}
return false;
}
Aggregations