use of org.onosproject.net.Path in project onos by opennetworkinglab.
the class PathListCommand method doExecute.
@Override
protected void doExecute() {
init();
DeviceService deviceService = get(DeviceService.class);
DeviceId srcDid = deviceId(src);
if (deviceService.getDevice(srcDid) == null) {
print("Unknown device %s", src);
return;
}
DeviceId dstDid = deviceId(dst);
if (deviceService.getDevice(dstDid) == null) {
print("Unknown device %s", dst);
return;
}
Set<? extends Path> paths;
if (disjoint) {
paths = service.getDisjointPaths(topology, srcDid, dstDid);
} else {
paths = service.getPaths(topology, srcDid, dstDid);
}
if (outputJson()) {
print("%s", json(this, paths));
} else {
for (Path path : paths) {
print(pathString(path));
if (path instanceof DisjointPath) {
// print backup right after primary
print(pathString(((DisjointPath) path).backup()));
}
}
}
}
use of org.onosproject.net.Path in project onos by opennetworkinglab.
the class PathListCommand method json.
/**
* Produces a JSON array containing the specified paths.
*
* @param context context to use for looking up codecs
* @param paths collection of paths
* @return JSON array
*/
public static JsonNode json(AbstractShellCommand context, Iterable<? extends Path> paths) {
ObjectMapper mapper = context.mapper();
ArrayNode result = mapper.createArrayNode();
for (Path path : paths) {
result.add(LinksListCommand.json(context, path).put("cost", path.cost()).set("links", LinksListCommand.json(context, path.links())));
if (path instanceof DisjointPath) {
// [ (primay), (backup), ...]
DisjointPath backup = (DisjointPath) path;
result.add(LinksListCommand.json(context, backup.backup()).put("cost", backup.cost()).set("links", LinksListCommand.json(context, backup.links())));
}
}
return result;
}
use of org.onosproject.net.Path in project onos by opennetworkinglab.
the class ReactiveForwarding method fixBlackhole.
private void fixBlackhole(ConnectPoint egress) {
Set<FlowEntry> rules = getFlowRulesFrom(egress);
Set<SrcDstPair> pairs = findSrcDstPairs(rules);
Map<DeviceId, Set<Path>> srcPaths = new HashMap<>();
for (SrcDstPair sd : pairs) {
// get the edge deviceID for the src host
Host srcHost = hostService.getHost(HostId.hostId(sd.src));
Host dstHost = hostService.getHost(HostId.hostId(sd.dst));
if (srcHost != null && dstHost != null) {
DeviceId srcId = srcHost.location().deviceId();
DeviceId dstId = dstHost.location().deviceId();
log.trace("SRC ID is {}, DST ID is {}", srcId, dstId);
cleanFlowRules(sd, egress.deviceId());
Set<Path> shortestPaths = srcPaths.get(srcId);
if (shortestPaths == null) {
shortestPaths = topologyService.getPaths(topologyService.currentTopology(), egress.deviceId(), srcId);
srcPaths.put(srcId, shortestPaths);
}
backTrackBadNodes(shortestPaths, dstId, sd);
}
}
}
use of org.onosproject.net.Path in project onos by opennetworkinglab.
the class OpticalPathProvisioner method setupConnectivity.
/*
* Request packet-layer connectivity between specified ports,
* over packet-optical multi-layer infrastructure.
*
* Functionality-wise this is effectively submitting Packet-Optical
* multi-layer P2P Intent.
*
* It computes multi-layer path meeting specified constraint,
* and calls setupPath.
*/
@Override
public OpticalConnectivityId setupConnectivity(ConnectPoint ingress, ConnectPoint egress, Bandwidth bandwidth, Duration latency) {
checkNotNull(ingress);
checkNotNull(egress);
log.info("setupConnectivity({}, {}, {}, {})", ingress, egress, bandwidth, latency);
Bandwidth bw = (bandwidth == null) ? NO_BW_REQUIREMENT : bandwidth;
Stream<Path> paths = topologyService.getKShortestPaths(topologyService.currentTopology(), ingress.deviceId(), egress.deviceId(), new BandwidthLinkWeight(bandwidth));
// Path service calculates from node to node, we're only interested in port to port
Optional<OpticalConnectivityId> id = paths.filter(p -> p.src().equals(ingress) && p.dst().equals(egress)).limit(maxPaths).map(p -> setupPath(p, bw, latency)).filter(Objects::nonNull).findFirst();
if (id.isPresent()) {
log.info("Assigned OpticalConnectivityId: {}", id);
} else {
log.error("setupConnectivity({}, {}, {}, {}) failed.", ingress, egress, bandwidth, latency);
}
return id.orElse(null);
}
use of org.onosproject.net.Path in project onos by opennetworkinglab.
the class GnpyManager method obtainConnectivity.
@Override
public Pair<IntentId, Double> obtainConnectivity(ConnectPoint ingress, ConnectPoint egress, boolean bidirectional) {
ByteArrayOutputStream connectivityRequest = createGnpyRequest(ingress, egress, bidirectional);
String response = gnpyHttpUtil.post(null, "/gnpy-experimental", new ByteArrayInputStream(connectivityRequest.toByteArray()), MediaType.APPLICATION_JSON_TYPE, String.class);
ObjectMapper om = new ObjectMapper();
final ObjectReader reader = om.reader();
JsonNode jsonNode;
try {
jsonNode = reader.readTree(response);
if (jsonNode == null) {
log.error("JsonNode is null for response {}", response);
return null;
}
log.info("Response {}", response);
String bestPath;
try {
bestPath = getBestOsnrPathKey(jsonNode);
} catch (IllegalStateException e) {
log.error("Exception while contacting GNPy", e);
return null;
}
OchSignal ochSignal = createOchSignal(jsonNode);
Map<DeviceId, Double> deviceAtoBPowerMap = new HashMap<>();
Map<DeviceId, Double> deviceBtoAPowerMap = new HashMap<>();
// TODO this list is currently only populated in the forward direction
List<DeviceId> deviceIds = getDeviceAndPopulatePowerMap(jsonNode, deviceAtoBPowerMap, deviceBtoAPowerMap, bestPath);
Path suggestedPath = createSuggestedPath(deviceIds);
log.info("Suggested path {}", suggestedPath);
Intent intent = createOpticalIntent(ingress, egress, deviceService, null, appId, bidirectional, ochSignal, suggestedPath);
intentsPowerMap.put(intent.id(), new GnpyPowerInfo(deviceAtoBPowerMap, deviceBtoAPowerMap, getLaunchPower(jsonNode), suggestedPath.links(), ingress, egress, ochSignal));
intentService.submit(intent);
return Pair.of(intent.id(), getOsnr(jsonNode, bestPath));
} catch (IOException e) {
log.error("Exception while reading response {}", response, e);
return null;
}
}
Aggregations