Search in sources :

Example 1 with DefaultLoad

use of org.onosproject.net.statistic.DefaultLoad in project onos by opennetworkinglab.

the class StatisticsResourceTest method setUpTest.

/**
 * Initializes test mocks and environment.
 */
@Before
public void setUpTest() {
    mockLinkService = createMock(LinkService.class);
    expect(mockLinkService.getLinks()).andReturn(ImmutableList.of(link1, link2, link3));
    expect(mockLinkService.getLinks(connectPoint("0000000000000001", 2))).andReturn(ImmutableSet.of(link3));
    mockStatisticService = createMock(StatisticService.class);
    expect(mockStatisticService.load(link1)).andReturn(new DefaultLoad(2, 1, 1));
    expect(mockStatisticService.load(link2)).andReturn(new DefaultLoad(22, 11, 1));
    expect(mockStatisticService.load(link3)).andReturn(new DefaultLoad(222, 111, 1));
    replay(mockLinkService, mockStatisticService);
    // Register the services needed for the test
    CodecManager codecService = new CodecManager();
    codecService.activate();
    ServiceDirectory testDirectory = new TestServiceDirectory().add(LinkService.class, mockLinkService).add(StatisticService.class, mockStatisticService).add(CodecService.class, codecService);
    setServiceDirectory(testDirectory);
}
Also used : ServiceDirectory(org.onlab.osgi.ServiceDirectory) TestServiceDirectory(org.onlab.osgi.TestServiceDirectory) StatisticService(org.onosproject.net.statistic.StatisticService) TestServiceDirectory(org.onlab.osgi.TestServiceDirectory) CodecManager(org.onosproject.codec.impl.CodecManager) LinkService(org.onosproject.net.link.LinkService) DefaultLoad(org.onosproject.net.statistic.DefaultLoad) Before(org.junit.Before)

Example 2 with DefaultLoad

use of org.onosproject.net.statistic.DefaultLoad in project onos by opennetworkinglab.

the class TrafficLinkTest method mergeStatsBytes.

@Test
public void mergeStatsBytes() {
    title("mergeStatsBytes");
    TrafficLink tla = createALink();
    tla.addLoad(new DefaultLoad(2000, 0));
    print(tla);
    TrafficLink tlb = createALink();
    tlb.addLoad(new DefaultLoad(3000, 0));
    print(tlb);
    tla.mergeStats(tlb);
    print(tla);
    assertEquals("mergedBytes", 5000, tla.bytes());
    assertEquals("mergeRate", 500, tla.rate());
}
Also used : DefaultLoad(org.onosproject.net.statistic.DefaultLoad) Test(org.junit.Test) AbstractUiImplTest(org.onosproject.ui.impl.AbstractUiImplTest)

Example 3 with DefaultLoad

use of org.onosproject.net.statistic.DefaultLoad in project onos by opennetworkinglab.

the class FlowStatisticManager method loadSummaryPortInternal.

private SummaryFlowEntryWithLoad loadSummaryPortInternal(ConnectPoint cp) {
    checkPermission(STATISTIC_READ);
    Set<FlowEntry> currentStats;
    Set<FlowEntry> previousStats;
    TypedStatistics typedStatistics;
    synchronized (statisticStore) {
        currentStats = statisticStore.getCurrentStatistic(cp);
        if (currentStats == null) {
            return new SummaryFlowEntryWithLoad(cp, new DefaultLoad());
        }
        previousStats = statisticStore.getPreviousStatistic(cp);
        if (previousStats == null) {
            return new SummaryFlowEntryWithLoad(cp, new DefaultLoad());
        }
        // copy to local flow entry
        typedStatistics = new TypedStatistics(currentStats, previousStats);
        // Check for validity of this stats data
        checkLoadValidity(currentStats, previousStats);
    }
    // current and previous set is not empty!
    Set<FlowEntry> currentSet = typedStatistics.current();
    Set<FlowEntry> previousSet = typedStatistics.previous();
    PollInterval pollIntervalInstance = PollInterval.getInstance();
    // We assume that default pollInterval is flowPollFrequency in case adaptiveFlowSampling is true or false
    Load totalLoad = new DefaultLoad(aggregateBytesSet(currentSet), aggregateBytesSet(previousSet), pollIntervalInstance.getPollInterval());
    Map<FlowRule, FlowEntry> currentMap;
    Map<FlowRule, FlowEntry> previousMap;
    currentMap = typedStatistics.currentImmediate();
    previousMap = typedStatistics.previousImmediate();
    Load immediateLoad = new DefaultLoad(aggregateBytesMap(currentMap), aggregateBytesMap(previousMap), pollIntervalInstance.getPollInterval());
    currentMap = typedStatistics.currentShort();
    previousMap = typedStatistics.previousShort();
    Load shortLoad = new DefaultLoad(aggregateBytesMap(currentMap), aggregateBytesMap(previousMap), pollIntervalInstance.getPollInterval());
    currentMap = typedStatistics.currentMid();
    previousMap = typedStatistics.previousMid();
    Load midLoad = new DefaultLoad(aggregateBytesMap(currentMap), aggregateBytesMap(previousMap), pollIntervalInstance.getMidPollInterval());
    currentMap = typedStatistics.currentLong();
    previousMap = typedStatistics.previousLong();
    Load longLoad = new DefaultLoad(aggregateBytesMap(currentMap), aggregateBytesMap(previousMap), pollIntervalInstance.getLongPollInterval());
    currentMap = typedStatistics.currentUnknown();
    previousMap = typedStatistics.previousUnknown();
    Load unknownLoad = new DefaultLoad(aggregateBytesMap(currentMap), aggregateBytesMap(previousMap), pollIntervalInstance.getPollInterval());
    return new SummaryFlowEntryWithLoad(cp, totalLoad, immediateLoad, shortLoad, midLoad, longLoad, unknownLoad);
}
Also used : DefaultLoad(org.onosproject.net.statistic.DefaultLoad) Load(org.onosproject.net.statistic.Load) SummaryFlowEntryWithLoad(org.onosproject.net.statistic.SummaryFlowEntryWithLoad) TypedFlowEntryWithLoad(org.onosproject.net.statistic.TypedFlowEntryWithLoad) FlowEntryWithLoad(org.onosproject.net.statistic.FlowEntryWithLoad) PollInterval(org.onosproject.net.statistic.PollInterval) SummaryFlowEntryWithLoad(org.onosproject.net.statistic.SummaryFlowEntryWithLoad) FlowRule(org.onosproject.net.flow.FlowRule) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultTypedFlowEntry(org.onosproject.net.flow.DefaultTypedFlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) TypedStoredFlowEntry(org.onosproject.net.flow.TypedStoredFlowEntry) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) DefaultLoad(org.onosproject.net.statistic.DefaultLoad)

Example 4 with DefaultLoad

use of org.onosproject.net.statistic.DefaultLoad in project onos by opennetworkinglab.

the class FlowStatisticManager method typedFlowEntryLoadByInstInternal.

private List<FlowEntryWithLoad> typedFlowEntryLoadByInstInternal(ConnectPoint cp, Map<FlowRule, FlowEntry> currentMap, Map<FlowRule, FlowEntry> previousMap, boolean isAllInstType, Instruction.Type instType) {
    List<FlowEntryWithLoad> fel = new ArrayList<>();
    currentMap.values().forEach(fe -> {
        if (isAllInstType || fe.treatment().allInstructions().stream().filter(i -> i.type() == instType).findAny().isPresent()) {
            long currentBytes = fe.bytes();
            long previousBytes = previousMap.getOrDefault(fe, new DefaultFlowEntry(fe)).bytes();
            long liveTypePollInterval = getLiveTypePollInterval(fe.liveType());
            Load fLoad = new DefaultLoad(currentBytes, previousBytes, liveTypePollInterval);
            fel.add(new FlowEntryWithLoad(cp, fe, fLoad));
        }
    });
    return fel;
}
Also used : SummaryFlowEntryWithLoad(org.onosproject.net.statistic.SummaryFlowEntryWithLoad) TypedFlowEntryWithLoad(org.onosproject.net.statistic.TypedFlowEntryWithLoad) FlowEntryWithLoad(org.onosproject.net.statistic.FlowEntryWithLoad) Comparators(org.onosproject.utils.Comparators) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) AppGuard.checkPermission(org.onosproject.security.AppGuard.checkPermission) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultLoad(org.onosproject.net.statistic.DefaultLoad) PollInterval(org.onosproject.net.statistic.PollInterval) DefaultTypedFlowEntry(org.onosproject.net.flow.DefaultTypedFlowEntry) HashMap(java.util.HashMap) ConnectPoint(org.onosproject.net.ConnectPoint) Load(org.onosproject.net.statistic.Load) ArrayList(java.util.ArrayList) SummaryFlowEntryWithLoad(org.onosproject.net.statistic.SummaryFlowEntryWithLoad) Component(org.osgi.service.component.annotations.Component) Port(org.onosproject.net.Port) Map(java.util.Map) Activate(org.osgi.service.component.annotations.Activate) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) Instruction(org.onosproject.net.flow.instructions.Instruction) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) MoreObjects(com.google.common.base.MoreObjects) TypedFlowEntryWithLoad(org.onosproject.net.statistic.TypedFlowEntryWithLoad) Set(java.util.Set) FlowEntryWithLoad(org.onosproject.net.statistic.FlowEntryWithLoad) Collectors(java.util.stream.Collectors) FlowStatisticService(org.onosproject.net.statistic.FlowStatisticService) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Objects(java.util.Objects) List(java.util.List) StatisticStore(org.onosproject.net.statistic.StatisticStore) TreeMap(java.util.TreeMap) Predicate(com.google.common.base.Predicate) FlowRule(org.onosproject.net.flow.FlowRule) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) TypedStoredFlowEntry(org.onosproject.net.flow.TypedStoredFlowEntry) STATISTIC_READ(org.onosproject.security.AppPermission.Type.STATISTIC_READ) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) Reference(org.osgi.service.component.annotations.Reference) DefaultLoad(org.onosproject.net.statistic.DefaultLoad) Load(org.onosproject.net.statistic.Load) SummaryFlowEntryWithLoad(org.onosproject.net.statistic.SummaryFlowEntryWithLoad) TypedFlowEntryWithLoad(org.onosproject.net.statistic.TypedFlowEntryWithLoad) FlowEntryWithLoad(org.onosproject.net.statistic.FlowEntryWithLoad) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) ArrayList(java.util.ArrayList) DefaultLoad(org.onosproject.net.statistic.DefaultLoad)

Example 5 with DefaultLoad

use of org.onosproject.net.statistic.DefaultLoad in project onos by opennetworkinglab.

the class PortStatisticsManager method load.

@Override
public Load load(ConnectPoint connectPoint, MetricType metricType) {
    DataPoint c = current.get(connectPoint);
    DataPoint p = previous.get(connectPoint);
    long now = System.currentTimeMillis();
    if (c != null && p != null && (now - c.time < STALE_LIMIT)) {
        if (c.time > p.time + SECOND) {
            long cve = getEgressValue(c.stats, metricType);
            long cvi = getIngressValue(c.stats, metricType);
            long pve = getEgressValue(p.stats, metricType);
            long pvi = getIngressValue(p.stats, metricType);
            // Use max of either Tx or Rx load as the total load of a port
            Load load = null;
            if (cve >= pve) {
                load = new DefaultLoad(cve, pve, (int) (c.time - p.time) / SECOND);
            }
            if (cvi >= pvi) {
                Load rcvLoad = new DefaultLoad(cvi, pvi, (int) (c.time - p.time) / SECOND);
                load = ((load == null) || (rcvLoad.rate() > load.rate())) ? rcvLoad : load;
            }
            return load;
        }
    }
    return null;
}
Also used : DefaultLoad(org.onosproject.net.statistic.DefaultLoad) Load(org.onosproject.net.statistic.Load) DefaultLoad(org.onosproject.net.statistic.DefaultLoad)

Aggregations

DefaultLoad (org.onosproject.net.statistic.DefaultLoad)9 Load (org.onosproject.net.statistic.Load)7 Test (org.junit.Test)3 Link (org.onosproject.net.Link)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 SummaryFlowEntryWithLoad (org.onosproject.net.statistic.SummaryFlowEntryWithLoad)2 TypedFlowEntryWithLoad (org.onosproject.net.statistic.TypedFlowEntryWithLoad)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 MoreObjects (com.google.common.base.MoreObjects)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Predicate (com.google.common.base.Predicate)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ArrayList (java.util.ArrayList)1