Search in sources :

Example 1 with TestYFlowBuilder

use of org.openkilda.wfm.share.yflow.TestYFlowBuilder in project open-kilda by telstra.

the class KildaEntryCacheServiceTest method shouldRefreshYFlowMeterCache.

@Test
public void shouldRefreshYFlowMeterCache() {
    FlowEndpoint sharedEndpoint = new FlowEndpoint(SRC_SWITCH_ID, 1);
    FlowEndpoint splitEndEndpoint = new FlowEndpoint(DST_SWITCH_ID, 2);
    Switch sharedSwitch = Switch.builder().switchId(sharedEndpoint.getSwitchId()).build();
    Switch splitEndSwitch = Switch.builder().switchId(splitEndEndpoint.getSwitchId()).build();
    Switch yPointSwitch = Switch.builder().switchId(TRANSIT_SWITCH_ID).build();
    Flow subFlowAlpha = new TestFlowBuilder().srcSwitch(sharedSwitch).destSwitch(splitEndSwitch).addTransitionEndpoint(sharedSwitch, sharedEndpoint.getPortNumber()).addTransitionEndpoint(yPointSwitch, 1).addTransitionEndpoint(yPointSwitch, 2).addTransitionEndpoint(splitEndSwitch, sharedEndpoint.getPortNumber()).build();
    Flow subFlowBeta = new TestFlowBuilder().srcSwitch(sharedSwitch).destSwitch(splitEndSwitch).addTransitionEndpoint(sharedSwitch, sharedEndpoint.getPortNumber()).addTransitionEndpoint(yPointSwitch, 1).addTransitionEndpoint(yPointSwitch, 2).addTransitionEndpoint(splitEndSwitch, sharedEndpoint.getPortNumber()).build();
    YFlow yFlow = new TestYFlowBuilder().sharedEndpoint(new YFlow.SharedEndpoint(sharedEndpoint.getSwitchId(), sharedEndpoint.getPortNumber())).sharedEndpointMeterId(new MeterId(100)).yPoint(yPointSwitch.getSwitchId()).meterId(new MeterId(110)).subFlow(new TestYSubFlowBuilder().flow(subFlowAlpha).sharedEndpointVlan(10).endpoint(new FlowEndpoint(DST_SWITCH_ID, 2, 30))).subFlow(new TestYSubFlowBuilder().flow(subFlowBeta).sharedEndpointVlan(20).endpoint(new FlowEndpoint(DST_SWITCH_ID, 2, 40))).build();
    when(flowRepository.findAll()).thenReturn(Collections.emptyList());
    when(yFlowRepository.findAll()).thenReturn(Collections.singletonList(yFlow));
    service.refreshCache();
    // shared endpoint
    service.completeAndForwardMeterStats(new MeterStatsData(yFlow.getSharedEndpoint().getSwitchId(), Collections.singletonList(new MeterStatsEntry(yFlow.getSharedEndpointMeterId().getValue(), 0, 0))));
    verify(carrier, atLeastOnce()).emitMeterStats(meterCacheCaptor.capture());
    List<MeterStatsAndDescriptor> statsEntries = meterCacheCaptor.getValue().getStatsEntries();
    assertDescriptionPopulation(statsEntries, 1, 1);
    assertMeterCache(statsEntries, yFlow.getSharedEndpointMeterId().getValue(), new YFlowDescriptor(yFlow.getSharedEndpoint().getSwitchId(), Y_FLOW_SHARED, yFlow.getYFlowId(), yFlow.getSharedEndpointMeterId()));
    // y-point
    service.completeAndForwardMeterStats(new MeterStatsData(yFlow.getYPoint(), Collections.singletonList(new MeterStatsEntry(yFlow.getMeterId().getValue(), 0, 0))));
    verify(carrier, atLeastOnce()).emitMeterStats(meterCacheCaptor.capture());
    statsEntries = meterCacheCaptor.getValue().getStatsEntries();
    assertDescriptionPopulation(statsEntries, 1, 1);
    assertMeterCache(statsEntries, yFlow.getMeterId().getValue(), new YFlowDescriptor(yFlow.getYPoint(), Y_FLOW_Y_POINT, yFlow.getYFlowId(), yFlow.getMeterId()));
}
Also used : YFlow(org.openkilda.model.YFlow) MeterStatsAndDescriptor(org.openkilda.wfm.topology.stats.model.MeterStatsAndDescriptor) TestFlowBuilder(org.openkilda.wfm.share.flow.TestFlowBuilder) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) TestYFlowBuilder(org.openkilda.wfm.share.yflow.TestYFlowBuilder) MeterId(org.openkilda.model.MeterId) MeterStatsData(org.openkilda.messaging.info.stats.MeterStatsData) FlowEndpoint(org.openkilda.model.FlowEndpoint) Switch(org.openkilda.model.Switch) YFlowDescriptor(org.openkilda.wfm.topology.stats.model.YFlowDescriptor) MeterStatsEntry(org.openkilda.messaging.info.stats.MeterStatsEntry) TestYSubFlowBuilder(org.openkilda.wfm.share.yflow.TestYSubFlowBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 MeterStatsData (org.openkilda.messaging.info.stats.MeterStatsData)1 MeterStatsEntry (org.openkilda.messaging.info.stats.MeterStatsEntry)1 Flow (org.openkilda.model.Flow)1 FlowEndpoint (org.openkilda.model.FlowEndpoint)1 MeterId (org.openkilda.model.MeterId)1 Switch (org.openkilda.model.Switch)1 YFlow (org.openkilda.model.YFlow)1 TestFlowBuilder (org.openkilda.wfm.share.flow.TestFlowBuilder)1 TestYFlowBuilder (org.openkilda.wfm.share.yflow.TestYFlowBuilder)1 TestYSubFlowBuilder (org.openkilda.wfm.share.yflow.TestYSubFlowBuilder)1 MeterStatsAndDescriptor (org.openkilda.wfm.topology.stats.model.MeterStatsAndDescriptor)1 YFlowDescriptor (org.openkilda.wfm.topology.stats.model.YFlowDescriptor)1