use of org.onosproject.net.statistic.Load in project onos by opennetworkinglab.
the class StatisticManager method max.
@Override
public Link max(Path path) {
checkPermission(STATISTIC_READ);
if (path.links().isEmpty()) {
return null;
}
Load maxLoad = new DefaultLoad();
Link maxLink = null;
for (Link link : path.links()) {
Load load = loadInternal(link.src());
if (load.rate() > maxLoad.rate()) {
maxLoad = load;
maxLink = link;
}
}
return maxLink;
}
use of org.onosproject.net.statistic.Load in project onos by opennetworkinglab.
the class StatisticsWebResource method getLoads.
/**
* Gets load statistics for all links or for a specific link.
*
* @onos.rsModel StatisticsFlowsLink
* @param deviceId (optional) device ID for a specific link
* @param port (optional) port number for a specified link
* @return 200 OK with JSON encoded array of Load objects
*/
@GET
@Path("flows/link")
@Produces(MediaType.APPLICATION_JSON)
public Response getLoads(@QueryParam("device") String deviceId, @QueryParam("port") String port) {
Iterable<Link> links;
if (deviceId == null || port == null) {
links = get(LinkService.class).getLinks();
} else {
ConnectPoint connectPoint = new ConnectPoint(deviceId(deviceId), portNumber(port));
links = get(LinkService.class).getLinks(connectPoint);
}
ObjectNode result = mapper().createObjectNode();
ArrayNode loads = mapper().createArrayNode();
JsonCodec<Load> loadCodec = codec(Load.class);
StatisticService statsService = getService(StatisticService.class);
StreamSupport.stream(Spliterators.spliteratorUnknownSize(links.iterator(), Spliterator.ORDERED), false).forEach(link -> {
ObjectNode loadNode = loadCodec.encode(statsService.load(link), this);
UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path("links").queryParam("device", link.src().deviceId().toString()).queryParam("port", link.src().port().toString());
loadNode.put("link", locationBuilder.build().toString());
loads.add(loadNode);
});
result.set("loads", loads);
return ok(result).build();
}
use of org.onosproject.net.statistic.Load in project onos by opennetworkinglab.
the class LoadCodecTest method testLoadEncode.
/**
* Tests encoding of a Load object.
*/
@Test
public void testLoadEncode() {
final long startTime = System.currentTimeMillis();
final Load load = new DefaultLoad(20, 10, 1);
final JsonNode node = new LoadCodec().encode(load, new MockCodecContext());
assertThat(node.get("valid").asBoolean(), is(true));
assertThat(node.get("latest").asLong(), is(20L));
assertThat(node.get("rate").asLong(), is(10L));
assertThat(node.get("time").asLong(), greaterThanOrEqualTo(startTime));
}
use of org.onosproject.net.statistic.Load in project onos by opennetworkinglab.
the class TrafficMonitorBase method attachPortLoad.
/**
* Processes the given traffic link to attach the "port load" attributed
* to the underlying topology links, for the specified metric type (either
* bytes/sec or packets/sec).
*
* @param link the traffic link to process
* @param metricType the metric type (bytes or packets)
*/
protected void attachPortLoad(TrafficLink link, MetricType metricType) {
// For bi-directional traffic links, use
// the max link rate of either direction
// (we choose 'one' since we know that is never null)
Link one = link.one();
Load egressSrc = services.portStats().load(one.src(), metricType);
Load egressDst = services.portStats().load(one.dst(), metricType);
link.addLoad(maxLoad(egressSrc, egressDst), metricType == BYTES ? BPS_THRESHOLD : 0);
}
use of org.onosproject.net.statistic.Load in project onos by opennetworkinglab.
the class TrafficLinkTest method basic.
@Test
public void basic() {
title("basic");
TrafficLink tl = createALink();
Load bigLoad = new DefaultLoad(2000, 0);
tl.addLoad(bigLoad);
print(tl);
assertEquals("bad bytes value", 2000, tl.bytes());
// NOTE: rate is bytes / period (10 seconds)
assertEquals("bad rate value", 200, tl.rate());
// this load does not represent flows
assertEquals("bad flow count", 0, tl.flows());
}
Aggregations