use of org.onosproject.net.Link in project onos by opennetworkinglab.
the class DisjointPathCodec method encode.
@Override
public ObjectNode encode(DisjointPath disjointPath, CodecContext context) {
checkNotNull(disjointPath, "Path cannot be null");
JsonCodec<Link> codec = context.codec(Link.class);
ObjectNode result = context.mapper().createObjectNode();
ObjectNode primary = context.mapper().createObjectNode().put("cost", disjointPath.primary().cost());
result.set("primary", primary);
ArrayNode jsonLinks = primary.putArray("links");
for (Link link : disjointPath.primary().links()) {
jsonLinks.add(codec.encode(link, context));
}
if (disjointPath.backup() != null) {
ObjectNode backup = context.mapper().createObjectNode().put("cost", disjointPath.backup().cost());
result.set("backup", backup);
ArrayNode jsonLinks1 = backup.putArray("links");
for (Link link1 : disjointPath.backup().links()) {
jsonLinks1.add(codec.encode(link1, context));
}
}
return annotate(result, disjointPath, context);
}
use of org.onosproject.net.Link in project onos by opennetworkinglab.
the class PathCodec method encode.
@Override
public ObjectNode encode(Path path, CodecContext context) {
checkNotNull(path, "Path cannot be null");
JsonCodec<Link> codec = context.codec(Link.class);
ObjectNode result = context.mapper().createObjectNode().put("cost", path.cost());
ArrayNode jsonLinks = result.putArray("links");
for (Link link : path.links()) {
jsonLinks.add(codec.encode(link, context));
}
return annotate(result, path, context);
}
use of org.onosproject.net.Link in project onos by opennetworkinglab.
the class TunnelQueryCommand method showPath.
private String showPath(Path path) {
if (path == null) {
return "null";
}
StringBuilder builder = new StringBuilder("(");
for (Link link : path.links()) {
builder.append("(DeviceId:" + link.src().deviceId() + " Port:" + link.src().port().toString());
builder.append(" DeviceId:" + link.dst().deviceId() + " Port:" + link.dst().port().toString() + ")");
}
builder.append(annotations(path.annotations()) + ")");
return builder.toString();
}
use of org.onosproject.net.Link in project onos by opennetworkinglab.
the class LinksListCommand method doExecute.
@Override
protected void doExecute() {
LinkService service = get(LinkService.class);
Iterable<Link> links = uri != null ? service.getDeviceLinks(deviceId(uri)) : service.getLinks();
if (outputJson()) {
print("%s", json(this, links));
} else {
Tools.stream(links).sorted(Comparator.comparing(link -> linkKey(link).toString())).forEach(link -> {
print(linkString(link));
});
}
}
use of org.onosproject.net.Link in project onos by opennetworkinglab.
the class LinkCollectionCompiler method computePorts.
/**
* Helper method to compute input and output ports
* for each device crossed in the path.
*
* @param intent the related intents
* @param inputPorts the input ports to compute
* @param outputPorts the output ports to compute
*/
protected void computePorts(LinkCollectionIntent intent, SetMultimap<DeviceId, PortNumber> inputPorts, SetMultimap<DeviceId, PortNumber> outputPorts) {
for (Link link : intent.links()) {
inputPorts.put(link.dst().deviceId(), link.dst().port());
outputPorts.put(link.src().deviceId(), link.src().port());
}
for (ConnectPoint ingressPoint : intent.ingressPoints()) {
inputPorts.put(ingressPoint.deviceId(), ingressPoint.port());
}
for (ConnectPoint egressPoint : intent.egressPoints()) {
outputPorts.put(egressPoint.deviceId(), egressPoint.port());
}
}
Aggregations