use of org.openkilda.wfm.topology.stats.model.FlowStatsAndDescriptor in project open-kilda by telstra.
the class FlowMetricGenBolt method handleInput.
@Override
protected void handleInput(Tuple input) throws Exception {
SwitchFlowStats stats = pullValue(input, STATS_FIELD, SwitchFlowStats.class);
log.debug("dataCache in FlowMetricGenBolt {}", stats);
long timestamp = pullContext(input).getCreateTime();
SwitchId switchId = stats.getSwitchId();
for (FlowStatsAndDescriptor entry : stats.getStatsEntries()) {
handleStatsEntry(entry.getData(), timestamp, switchId, entry.getDescriptor());
}
}
use of org.openkilda.wfm.topology.stats.model.FlowStatsAndDescriptor in project open-kilda by telstra.
the class KildaEntryCacheServiceTest method shouldHandleRemovingFlowFromCache.
@Test
public void shouldHandleRemovingFlowFromCache() {
Flow flow = buildFlow();
FlowStatsData statsOrigin = getFlowStatsDataSrcSwitch();
service.completeAndForwardFlowStats(statsOrigin);
verify(carrier, atLeastOnce()).emitFlowStats(cookieCacheCaptor.capture());
List<FlowStatsAndDescriptor> statsEntries = cookieCacheCaptor.getValue().getStatsEntries();
assertDescriptionPopulation(statsEntries, statsOrigin.getStats().size(), 0);
FlowPath forwardPath = flow.getForwardPath();
UpdateFlowPathInfo pathInfo = new UpdateFlowPathInfo(flow.getFlowId(), flow.getYFlowId(), forwardPath.getCookie(), forwardPath.getMeterId(), FlowPathMapper.INSTANCE.mapToPathNodes(forwardPath));
service.addOrUpdateCache(pathInfo);
service.completeAndForwardFlowStats(statsOrigin);
verify(carrier, atLeastOnce()).emitFlowStats(cookieCacheCaptor.capture());
statsEntries = cookieCacheCaptor.getValue().getStatsEntries();
assertDescriptionPopulation(statsEntries, statsOrigin.getStats().size(), 1);
assertCookieCache(statsEntries, forwardPath.getCookie(), new CommonFlowDescriptor(flow.getSrcSwitchId(), INGRESS, flow.getFlowId(), forwardPath.getCookie(), forwardPath.getMeterId()));
RemoveFlowPathInfo pathInfo2 = new RemoveFlowPathInfo(flow.getFlowId(), flow.getYFlowId(), forwardPath.getCookie(), forwardPath.getMeterId(), FlowPathMapper.INSTANCE.mapToPathNodes(forwardPath));
service.removeCached(pathInfo2);
service.completeAndForwardFlowStats(statsOrigin);
verify(carrier, atLeastOnce()).emitFlowStats(cookieCacheCaptor.capture());
statsEntries = cookieCacheCaptor.getValue().getStatsEntries();
assertDescriptionPopulation(statsEntries, statsOrigin.getStats().size(), 0);
}
use of org.openkilda.wfm.topology.stats.model.FlowStatsAndDescriptor in project open-kilda by telstra.
the class KildaEntryCacheServiceTest method assertCookieCache.
private void assertCookieCache(List<FlowStatsAndDescriptor> statsEntries, FlowSegmentCookie cookie, KildaEntryDescriptor expectedDescriptor) {
long needle = cookie.getValue();
for (FlowStatsAndDescriptor entry : statsEntries) {
if (needle == entry.getData().getCookie()) {
KildaEntryDescriptor descriptor = entry.getDescriptor();
Assert.assertEquals(expectedDescriptor, descriptor);
return;
}
}
Assert.fail("Cache miss");
}
use of org.openkilda.wfm.topology.stats.model.FlowStatsAndDescriptor in project open-kilda by telstra.
the class KildaEntryCacheServiceTest method shouldRefreshYFlowSubFlowCookieCache.
@Test
public void shouldRefreshYFlowSubFlowCookieCache() {
Switch srcSwitch = Switch.builder().switchId(SRC_SWITCH_ID).build();
Switch destSwitch = Switch.builder().switchId(DST_SWITCH_ID).build();
Switch transitSwitch = Switch.builder().switchId(TRANSIT_SWITCH_ID).build();
Flow flow = new TestFlowBuilder().yFlowId("dummy-y-flow-id").srcSwitch(srcSwitch).addTransitionEndpoint(srcSwitch, 2).addTransitionEndpoint(transitSwitch, 1).addTransitionEndpoint(transitSwitch, 2).addTransitionEndpoint(destSwitch, 1).unmaskedCookie(FLOW_UNMASKED_COOKIE).forwardMeterId(FORWARD_METER_ID).reverseMeterId(REVERSE_METER_ID).destSwitch(destSwitch).build();
when(flowRepository.findAll()).thenReturn(Collections.singletonList(flow));
when(yFlowRepository.findAll()).thenReturn(Collections.emptyList());
service.refreshCache();
final FlowSegmentCookie forwardPathCookie = flow.getForwardPath().getCookie();
final FlowSegmentCookie reversePathCookie = flow.getReversePath().getCookie();
// source switch
service.completeAndForwardFlowStats(new FlowStatsData(flow.getSrcSwitchId(), asList(new FlowStatsEntry(0, forwardPathCookie.getValue(), 0, 0, 0, 0), new FlowStatsEntry(0, reversePathCookie.getValue(), 0, 0, 0, 0))));
verify(carrier, atLeastOnce()).emitFlowStats(cookieCacheCaptor.capture());
List<FlowStatsAndDescriptor> statsEntries = cookieCacheCaptor.getValue().getStatsEntries();
assertDescriptionPopulation(statsEntries, 2, 2);
assertCookieCache(statsEntries, forwardPathCookie, new YFlowSubDescriptor(flow.getSrcSwitchId(), INGRESS, flow.getYFlowId(), flow.getFlowId(), forwardPathCookie, flow.getForwardPath().getMeterId()));
assertCookieCache(statsEntries, reversePathCookie, new YFlowSubDescriptor(flow.getSrcSwitchId(), EGRESS, flow.getYFlowId(), flow.getFlowId(), reversePathCookie, null));
// transit
service.completeAndForwardFlowStats(new FlowStatsData(transitSwitch.getSwitchId(), asList(new FlowStatsEntry(0, forwardPathCookie.getValue(), 0, 0, 0, 0), new FlowStatsEntry(0, reversePathCookie.getValue(), 0, 0, 0, 0))));
verify(carrier, atLeastOnce()).emitFlowStats(cookieCacheCaptor.capture());
statsEntries = cookieCacheCaptor.getValue().getStatsEntries();
assertDescriptionPopulation(statsEntries, 2, 2);
assertCookieCache(statsEntries, forwardPathCookie, new YFlowSubDescriptor(transitSwitch.getSwitchId(), TRANSIT, flow.getYFlowId(), flow.getFlowId(), forwardPathCookie, null));
assertCookieCache(statsEntries, reversePathCookie, new YFlowSubDescriptor(transitSwitch.getSwitchId(), TRANSIT, flow.getYFlowId(), flow.getFlowId(), reversePathCookie, null));
// egress
service.completeAndForwardFlowStats(new FlowStatsData(flow.getDestSwitchId(), asList(new FlowStatsEntry(0, forwardPathCookie.getValue(), 0, 0, 0, 0), new FlowStatsEntry(0, reversePathCookie.getValue(), 0, 0, 0, 0))));
verify(carrier, atLeastOnce()).emitFlowStats(cookieCacheCaptor.capture());
statsEntries = cookieCacheCaptor.getValue().getStatsEntries();
assertDescriptionPopulation(statsEntries, 2, 2);
assertCookieCache(statsEntries, forwardPathCookie, new YFlowSubDescriptor(flow.getDestSwitchId(), EGRESS, flow.getYFlowId(), flow.getFlowId(), forwardPathCookie, null));
assertCookieCache(statsEntries, reversePathCookie, new YFlowSubDescriptor(flow.getDestSwitchId(), INGRESS, flow.getYFlowId(), flow.getFlowId(), reversePathCookie, flow.getReversePath().getMeterId()));
}
use of org.openkilda.wfm.topology.stats.model.FlowStatsAndDescriptor in project open-kilda by telstra.
the class KildaEntryCacheServiceTest method shouldRefreshCommonFlowsCookieCache.
@Test
public void shouldRefreshCommonFlowsCookieCache() {
Flow flow = buildFlow();
when(flowRepository.findAll()).thenReturn(Collections.singletonList(flow));
when(yFlowRepository.findAll()).thenReturn(Collections.emptyList());
service.refreshCache();
final FlowPath forwardPath = flow.getForwardPath();
FlowStatsData statsOriginSrc = getFlowStatsDataSrcSwitch();
service.completeAndForwardFlowStats(statsOriginSrc);
verify(carrier, atLeastOnce()).emitFlowStats(cookieCacheCaptor.capture());
List<FlowStatsAndDescriptor> statsEntries = cookieCacheCaptor.getValue().getStatsEntries();
assertDescriptionPopulation(statsEntries, statsOriginSrc.getStats().size(), 3);
assertCookieCache(statsEntries, forwardPath.getCookie(), new CommonFlowDescriptor(flow.getSrcSwitchId(), INGRESS, flow.getFlowId(), forwardPath.getCookie(), flow.getForwardPath().getMeterId()));
assertCookieCache(statsEntries, REVERSE_PATH_COOKIE, new CommonFlowDescriptor(flow.getSrcSwitchId(), EGRESS, flow.getFlowId(), REVERSE_PATH_COOKIE, null));
assertCookieCache(statsEntries, PROTECTED_REVERSE_PATH_COOKIE, new CommonFlowDescriptor(flow.getSrcSwitchId(), EGRESS, flow.getFlowId(), PROTECTED_REVERSE_PATH_COOKIE, null));
FlowStatsData statsOriginDst = getFlowStatsDataDstSwitch();
service.completeAndForwardFlowStats(statsOriginDst);
verify(carrier, atLeastOnce()).emitFlowStats(cookieCacheCaptor.capture());
statsEntries = cookieCacheCaptor.getValue().getStatsEntries();
assertDescriptionPopulation(statsEntries, statsOriginDst.getStats().size(), 3);
assertCookieCache(statsEntries, forwardPath.getCookie(), new CommonFlowDescriptor(flow.getDestSwitchId(), EGRESS, flow.getFlowId(), forwardPath.getCookie(), null));
assertCookieCache(statsEntries, REVERSE_PATH_COOKIE, new CommonFlowDescriptor(flow.getDestSwitchId(), INGRESS, flow.getFlowId(), REVERSE_PATH_COOKIE, flow.getReversePath().getMeterId()));
assertCookieCache(statsEntries, PROTECTED_FORWARD_PATH_COOKIE, new CommonFlowDescriptor(flow.getDestSwitchId(), EGRESS, flow.getFlowId(), PROTECTED_FORWARD_PATH_COOKIE, null));
FlowStatsData statsOriginTransit = getFlowStatsDataTransitSwitch();
service.completeAndForwardFlowStats(statsOriginTransit);
verify(carrier, atLeastOnce()).emitFlowStats(cookieCacheCaptor.capture());
statsEntries = cookieCacheCaptor.getValue().getStatsEntries();
assertDescriptionPopulation(statsEntries, statsOriginTransit.getStats().size(), 4);
assertCookieCache(statsEntries, forwardPath.getCookie(), new CommonFlowDescriptor(TRANSIT_SWITCH_ID, TRANSIT, flow.getFlowId(), forwardPath.getCookie(), null));
assertCookieCache(statsEntries, REVERSE_PATH_COOKIE, new CommonFlowDescriptor(TRANSIT_SWITCH_ID, TRANSIT, flow.getFlowId(), REVERSE_PATH_COOKIE, null));
assertCookieCache(statsEntries, PROTECTED_FORWARD_PATH_COOKIE, new CommonFlowDescriptor(TRANSIT_SWITCH_ID, TRANSIT, flow.getFlowId(), PROTECTED_FORWARD_PATH_COOKIE, null));
assertCookieCache(statsEntries, PROTECTED_REVERSE_PATH_COOKIE, new CommonFlowDescriptor(TRANSIT_SWITCH_ID, TRANSIT, flow.getFlowId(), PROTECTED_REVERSE_PATH_COOKIE, null));
// flow endpoint satellites
service.completeAndForwardFlowStats(new FlowStatsData(flow.getSrcSwitchId(), asList(new FlowStatsEntry(0, forwardPath.getCookie().toBuilder().type(CookieType.SERVER_42_FLOW_RTT_INGRESS).build().getValue(), 0, 0, 0, 0), new FlowStatsEntry(0, forwardPath.getCookie().toBuilder().mirror(true).build().getValue(), 0, 0, 0, 0), new FlowStatsEntry(0, forwardPath.getCookie().toBuilder().looped(true).build().getValue(), 0, 0, 0, 0))));
verify(carrier, atLeastOnce()).emitFlowStats(cookieCacheCaptor.capture());
statsEntries = cookieCacheCaptor.getValue().getStatsEntries();
assertDescriptionPopulation(statsEntries, 3, 3);
assertCookieCache(statsEntries, forwardPath.getCookie().toBuilder().type(CookieType.SERVER_42_FLOW_RTT_INGRESS).build(), new CommonFlowDescriptor(flow.getSrcSwitchId(), INGRESS, flow.getFlowId(), forwardPath.getCookie(), forwardPath.getMeterId()));
assertCookieCache(statsEntries, forwardPath.getCookie().toBuilder().mirror(true).build(), new CommonFlowDescriptor(flow.getSrcSwitchId(), INGRESS, flow.getFlowId(), forwardPath.getCookie(), forwardPath.getMeterId()));
assertCookieCache(statsEntries, forwardPath.getCookie().toBuilder().looped(true).build(), new CommonFlowDescriptor(flow.getSrcSwitchId(), INGRESS, flow.getFlowId(), forwardPath.getCookie(), forwardPath.getMeterId()));
}
Aggregations