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