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);
}
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());
}
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);
}
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;
}
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;
}
Aggregations