Search in sources :

Example 6 with Load

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;
}
Also used : DefaultLoad(org.onosproject.net.statistic.DefaultLoad) Load(org.onosproject.net.statistic.Load) DefaultLoad(org.onosproject.net.statistic.DefaultLoad) Link(org.onosproject.net.Link)

Example 7 with Load

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();
}
Also used : Load(org.onosproject.net.statistic.Load) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) StatisticService(org.onosproject.net.statistic.StatisticService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) UriBuilder(javax.ws.rs.core.UriBuilder) ConnectPoint(org.onosproject.net.ConnectPoint) Link(org.onosproject.net.Link) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 8 with Load

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));
}
Also used : DefaultLoad(org.onosproject.net.statistic.DefaultLoad) Load(org.onosproject.net.statistic.Load) JsonNode(com.fasterxml.jackson.databind.JsonNode) DefaultLoad(org.onosproject.net.statistic.DefaultLoad) Test(org.junit.Test)

Example 9 with Load

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);
}
Also used : Load(org.onosproject.net.statistic.Load) DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) Link(org.onosproject.net.Link) DefaultEdgeLink(org.onosproject.net.DefaultEdgeLink) TrafficLink(org.onosproject.ui.impl.topo.util.TrafficLink)

Example 10 with Load

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());
}
Also used : DefaultLoad(org.onosproject.net.statistic.DefaultLoad) Load(org.onosproject.net.statistic.Load) DefaultLoad(org.onosproject.net.statistic.DefaultLoad) Test(org.junit.Test) AbstractUiImplTest(org.onosproject.ui.impl.AbstractUiImplTest)

Aggregations

Load (org.onosproject.net.statistic.Load)10 DefaultLoad (org.onosproject.net.statistic.DefaultLoad)7 Link (org.onosproject.net.Link)4 ConnectPoint (org.onosproject.net.ConnectPoint)3 Test (org.junit.Test)2 PortNumber (org.onosproject.net.PortNumber)2 DefaultFlowEntry (org.onosproject.net.flow.DefaultFlowEntry)2 DefaultTypedFlowEntry (org.onosproject.net.flow.DefaultTypedFlowEntry)2 FlowEntry (org.onosproject.net.flow.FlowEntry)2 FlowRule (org.onosproject.net.flow.FlowRule)2 StoredFlowEntry (org.onosproject.net.flow.StoredFlowEntry)2 TypedStoredFlowEntry (org.onosproject.net.flow.TypedStoredFlowEntry)2 FlowEntryWithLoad (org.onosproject.net.statistic.FlowEntryWithLoad)2 PollInterval (org.onosproject.net.statistic.PollInterval)2 StatisticService (org.onosproject.net.statistic.StatisticService)2 SummaryFlowEntryWithLoad (org.onosproject.net.statistic.SummaryFlowEntryWithLoad)2 TypedFlowEntryWithLoad (org.onosproject.net.statistic.TypedFlowEntryWithLoad)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1