Search in sources :

Example 31 with SwitchId

use of org.openkilda.model.SwitchId in project open-kilda by telstra.

the class YFlowValidationHubServiceTest method handleSpeakerRequests.

private void handleSpeakerRequests(YFlowValidationHubService service, String yFlowFsmKey, Map<SwitchId, Collection<FlowEntry>> flowEntries, Map<SwitchId, Collection<MeterEntry>> meterEntries, Map<SwitchId, Collection<GroupEntry>> groupEntries) {
    handleSpeakerRequests(pair -> {
        CommandData commandData = pair.getValue();
        InfoData result = null;
        if (commandData instanceof DumpRulesForFlowHsRequest) {
            SwitchId switchId = ((DumpRulesForFlowHsRequest) commandData).getSwitchId();
            Collection<FlowEntry> foundFlowEntries = flowEntries.get(switchId);
            result = SwitchFlowEntries.builder().switchId(switchId).flowEntries(foundFlowEntries != null ? new ArrayList<>(foundFlowEntries) : emptyList()).build();
        } else if (commandData instanceof DumpMetersForFlowHsRequest) {
            SwitchId switchId = ((DumpMetersForFlowHsRequest) commandData).getSwitchId();
            Collection<MeterEntry> foundMeterEntries = meterEntries.get(switchId);
            result = SwitchMeterEntries.builder().switchId(switchId).meterEntries(foundMeterEntries != null ? new ArrayList<>(foundMeterEntries) : emptyList()).build();
        } else if (commandData instanceof DumpGroupsForFlowHsRequest) {
            SwitchId switchId = ((DumpGroupsForFlowHsRequest) commandData).getSwitchId();
            Collection<GroupEntry> foundGroupEntries = groupEntries.get(switchId);
            result = SwitchGroupEntries.builder().switchId(switchId).groupEntries(foundGroupEntries != null ? new ArrayList<>(foundGroupEntries) : emptyList()).build();
        } else {
            fail();
        }
        String flowId = pair.getKey();
        service.handleAsyncResponse(yFlowFsmKey, flowId, result);
    });
}
Also used : DumpGroupsForFlowHsRequest(org.openkilda.messaging.command.switches.DumpGroupsForFlowHsRequest) GroupEntry(org.openkilda.messaging.info.rule.GroupEntry) ArrayList(java.util.ArrayList) SwitchId(org.openkilda.model.SwitchId) DumpMetersForFlowHsRequest(org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest) InfoData(org.openkilda.messaging.info.InfoData) DumpRulesForFlowHsRequest(org.openkilda.messaging.command.switches.DumpRulesForFlowHsRequest) Collection(java.util.Collection) CommandData(org.openkilda.messaging.command.CommandData) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry)

Example 32 with SwitchId

use of org.openkilda.model.SwitchId in project open-kilda by telstra.

the class YFlowUpdateServiceTest method shouldFailOnTimeoutDuringMeterInstallation.

@Test
public void shouldFailOnTimeoutDuringMeterInstallation() throws UnroutableFlowException, RecoverableException, DuplicateKeyException, UnknownKeyException {
    // given
    YFlowRequest request = createYFlow();
    request.setMaximumBandwidth(2000L);
    request.getSubFlows().get(0).setEndpoint(newFirstEndpoint);
    request.getSubFlows().get(1).setEndpoint(newSecondEndpoint);
    preparePathComputationForUpdate("test_flow_1", buildNewFirstSubFlowPathPair(), buildFirstSubFlowPathPair());
    preparePathComputationForUpdate("test_flow_2", buildNewSecondSubFlowPathPair(), buildSecondSubFlowPathPair());
    prepareYPointComputation(SWITCH_SHARED, SWITCH_NEW_FIRST_EP, SWITCH_NEW_SECOND_EP, SWITCH_TRANSIT);
    YFlowUpdateService service = makeYFlowUpdateService(0);
    // when
    service.handleRequest(request.getYFlowId(), new CommandContext(), request);
    verifyYFlowStatus(request.getYFlowId(), FlowStatus.IN_PROGRESS);
    // and
    handleSpeakerCommandsAndTimeoutInstall(service, request.getYFlowId());
    // then
    verifyYFlowStatus(request.getYFlowId(), FlowStatus.UP);
    YFlow flow = getYFlow(request.getYFlowId());
    assertEquals(1000L, flow.getMaximumBandwidth());
    Set<SwitchId> expectedEndpointSwitchIds = Stream.of(SWITCH_FIRST_EP, SWITCH_SECOND_EP).collect(Collectors.toSet());
    Set<SwitchId> actualEndpointSwitchIds = flow.getSubFlows().stream().map(YSubFlow::getEndpointSwitchId).collect(Collectors.toSet());
    assertEquals(expectedEndpointSwitchIds, actualEndpointSwitchIds);
}
Also used : YFlow(org.openkilda.model.YFlow) CommandContext(org.openkilda.wfm.CommandContext) SwitchId(org.openkilda.model.SwitchId) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) Test(org.junit.Test) AbstractYFlowTest(org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)

Example 33 with SwitchId

use of org.openkilda.model.SwitchId in project open-kilda by telstra.

the class YFlowUpdateServiceTest method shouldUpdateFlowWithTransitSwitches.

@Test
public void shouldUpdateFlowWithTransitSwitches() throws UnroutableFlowException, RecoverableException, DuplicateKeyException {
    // given
    YFlowRequest request = createYFlow();
    request.setMaximumBandwidth(2000L);
    request.getSubFlows().get(0).setEndpoint(newFirstEndpoint);
    request.getSubFlows().get(1).setEndpoint(newSecondEndpoint);
    preparePathComputationForUpdate("test_flow_1", buildNewFirstSubFlowPathPair());
    preparePathComputationForUpdate("test_flow_2", buildNewSecondSubFlowPathPair());
    prepareYPointComputation(SWITCH_SHARED, SWITCH_NEW_FIRST_EP, SWITCH_NEW_SECOND_EP, SWITCH_TRANSIT);
    // when
    processUpdateRequestAndSpeakerCommands(request);
    verifyNorthboundSuccessResponse(yFlowUpdateHubCarrier, YFlowResponse.class);
    verifyYFlowStatus(request.getYFlowId(), FlowStatus.UP);
    verifyAffinity(request.getYFlowId());
    YFlow flow = getYFlow(request.getYFlowId());
    assertEquals(2000L, flow.getMaximumBandwidth());
    Set<SwitchId> expectedEndpointSwitchIds = Stream.of(SWITCH_NEW_FIRST_EP, SWITCH_NEW_SECOND_EP).collect(Collectors.toSet());
    Set<SwitchId> actualEndpointSwitchIds = flow.getSubFlows().stream().map(YSubFlow::getEndpointSwitchId).collect(Collectors.toSet());
    assertEquals(expectedEndpointSwitchIds, actualEndpointSwitchIds);
}
Also used : YFlow(org.openkilda.model.YFlow) SwitchId(org.openkilda.model.SwitchId) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) Test(org.junit.Test) AbstractYFlowTest(org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)

Example 34 with SwitchId

use of org.openkilda.model.SwitchId in project open-kilda by telstra.

the class YFlowUpdateServiceTest method shouldPatchFlowWithTransitSwitches.

@Test
public void shouldPatchFlowWithTransitSwitches() throws UnroutableFlowException, RecoverableException, DuplicateKeyException {
    // given
    createYFlow();
    List<SubFlowPartialUpdateDto> subFlowPartialUpdateDtos = new ArrayList<>();
    subFlowPartialUpdateDtos.add(SubFlowPartialUpdateDto.builder().flowId("test_flow_1").endpoint(FlowPartialUpdateEndpoint.builder().switchId(SWITCH_NEW_FIRST_EP).portNumber(2).vlanId(103).build()).build());
    subFlowPartialUpdateDtos.add(SubFlowPartialUpdateDto.builder().flowId("test_flow_2").endpoint(FlowPartialUpdateEndpoint.builder().switchId(SWITCH_NEW_SECOND_EP).portNumber(3).vlanId(104).build()).build());
    YFlowPartialUpdateRequest request = YFlowPartialUpdateRequest.builder().yFlowId("test_successful_yflow").maximumBandwidth(2000L).subFlows(subFlowPartialUpdateDtos).build();
    preparePathComputationForUpdate("test_flow_1", buildNewFirstSubFlowPathPair());
    preparePathComputationForUpdate("test_flow_2", buildNewSecondSubFlowPathPair());
    prepareYPointComputation(SWITCH_SHARED, SWITCH_NEW_FIRST_EP, SWITCH_NEW_SECOND_EP, SWITCH_TRANSIT);
    // when
    processUpdateRequestAndSpeakerCommands(request);
    verifyNorthboundSuccessResponse(yFlowUpdateHubCarrier, YFlowResponse.class);
    verifyYFlowStatus(request.getYFlowId(), FlowStatus.UP);
    YFlow flow = getYFlow(request.getYFlowId());
    assertEquals(2000L, flow.getMaximumBandwidth());
    Set<SwitchId> expectedEndpointSwitchIds = Stream.of(SWITCH_NEW_FIRST_EP, SWITCH_NEW_SECOND_EP).collect(Collectors.toSet());
    Set<SwitchId> actualEndpointSwitchIds = flow.getSubFlows().stream().map(YSubFlow::getEndpointSwitchId).collect(Collectors.toSet());
    assertEquals(expectedEndpointSwitchIds, actualEndpointSwitchIds);
}
Also used : YFlow(org.openkilda.model.YFlow) ArrayList(java.util.ArrayList) SwitchId(org.openkilda.model.SwitchId) SubFlowPartialUpdateDto(org.openkilda.messaging.command.yflow.SubFlowPartialUpdateDto) YFlowPartialUpdateRequest(org.openkilda.messaging.command.yflow.YFlowPartialUpdateRequest) Test(org.junit.Test) AbstractYFlowTest(org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)

Example 35 with SwitchId

use of org.openkilda.model.SwitchId in project open-kilda by telstra.

the class ResponseSerialisationTest method getPacketInOutStatsResponseTest.

@Test
public void getPacketInOutStatsResponseTest() throws IOException {
    GetPacketInOutStatsResponse response = new GetPacketInOutStatsResponse(new SwitchId(1), new PacketInOutStatsDto(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, true, 11));
    String jsonString = mapper.writeValueAsString(response);
    GetPacketInOutStatsResponse objectFromJson = mapper.readValue(jsonString, GetPacketInOutStatsResponse.class);
    Assert.assertEquals(response, objectFromJson);
}
Also used : PacketInOutStatsDto(org.openkilda.messaging.model.grpc.PacketInOutStatsDto) SwitchId(org.openkilda.model.SwitchId) Test(org.junit.Test)

Aggregations

SwitchId (org.openkilda.model.SwitchId)339 Test (org.junit.Test)149 Flow (org.openkilda.model.Flow)73 Switch (org.openkilda.model.Switch)69 List (java.util.List)59 FlowPath (org.openkilda.model.FlowPath)49 ArrayList (java.util.ArrayList)44 Collectors (java.util.stream.Collectors)37 PathId (org.openkilda.model.PathId)36 PathComputer (org.openkilda.pce.PathComputer)35 Set (java.util.Set)34 YFlow (org.openkilda.model.YFlow)33 Map (java.util.Map)30 GetPathsResult (org.openkilda.pce.GetPathsResult)30 InfoMessage (org.openkilda.messaging.info.InfoMessage)29 String.format (java.lang.String.format)28 HashSet (java.util.HashSet)27 Optional (java.util.Optional)27 Collection (java.util.Collection)26 Collections (java.util.Collections)26