use of org.openkilda.model.PathId in project open-kilda by telstra.
the class BaseResourceAllocationActionTest method updateAvailableBandwidthFailsOnOverProvisionTest.
@Test(expected = ResourceAllocationException.class)
public void updateAvailableBandwidthFailsOnOverProvisionTest() throws ResourceAllocationException {
islRepositorySpy = spy(persistenceManager.getRepositoryFactory().createIslRepository());
when(repositoryFactory.createIslRepository()).thenReturn(islRepositorySpy);
doReturn(-1L).when(islRepositorySpy).updateAvailableBandwidth(any(), anyInt(), any(), anyInt());
BaseResourceAllocationAction action = mock(BaseResourceAllocationAction.class, Mockito.withSettings().useConstructor(persistenceManager, 3, 3, 3, pathComputer, resourcesManager, dashboardLogger).defaultAnswer(Mockito.CALLS_REAL_METHODS));
PathSegment segment = PathSegment.builder().pathId(new PathId("")).srcSwitch(Switch.builder().switchId(new SwitchId(1)).build()).srcPort(1).destSwitch(Switch.builder().switchId(new SwitchId(2)).build()).destPort(2).build();
action.createPathSegments(singletonList(segment), Suppliers.ofInstance(emptyMap()));
}
use of org.openkilda.model.PathId in project open-kilda by telstra.
the class FlowRerouteServiceTest method shouldFailRerouteOnErrorDuringCompletingFlowPathInstallation.
@Test
public void shouldFailRerouteOnErrorDuringCompletingFlowPathInstallation() throws RecoverableException, UnroutableFlowException, UnknownKeyException {
Flow origin = makeFlow();
preparePathComputation(origin.getFlowId(), make3SwitchesPathPair());
FlowPathRepository repository = setupFlowPathRepositorySpy();
Set<PathId> originalPaths = origin.getPaths().stream().map(FlowPath::getPathId).collect(toSet());
doThrow(new RuntimeException(injectedErrorMessage)).when(repository).updateStatus(ArgumentMatchers.argThat(argument -> !originalPaths.contains(argument)), eq(FlowPathStatus.ACTIVE));
FlowRerouteService service = makeService();
FlowRerouteRequest request = new FlowRerouteRequest(origin.getFlowId(), false, false, false, Collections.emptySet(), null, false);
service.handleRequest(currentRequestKey, request, commandContext);
verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
verifyNorthboundSuccessResponse(carrier);
FlowSegmentRequest speakerRequest;
while ((speakerRequest = requests.poll()) != null) {
if (speakerRequest.isVerifyRequest()) {
service.handleAsyncResponse(currentRequestKey, buildResponseOnVerifyRequest(speakerRequest));
} else {
produceAsyncResponse(service, speakerRequest);
}
}
Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
verifyNoPathReplace(origin, result);
}
use of org.openkilda.model.PathId in project open-kilda by telstra.
the class FlowUpdateServiceTest method shouldFailUpdateOnErrorDuringCompletingFlowPathInstallation.
@Test
public void shouldFailUpdateOnErrorDuringCompletingFlowPathInstallation() throws RecoverableException, UnroutableFlowException, DuplicateKeyException, UnknownKeyException {
Flow origin = makeFlow();
preparePathComputation(origin.getFlowId(), make3SwitchesPathPair());
FlowRequest request = makeRequest().flowId(origin.getFlowId()).build();
FlowPathRepository repository = setupFlowPathRepositorySpy();
Set<PathId> originalPaths = origin.getPaths().stream().map(FlowPath::getPathId).collect(Collectors.toSet());
doThrow(new RuntimeException(injectedErrorMessage)).when(repository).updateStatus(ArgumentMatchers.argThat(argument -> !originalPaths.contains(argument)), eq(FlowPathStatus.ACTIVE));
FlowUpdateService service = makeService();
service.handleUpdateRequest(dummyRequestKey, commandContext, request);
verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
verifyNorthboundSuccessResponse(carrier);
FlowSegmentRequest speakerRequest;
while ((speakerRequest = requests.poll()) != null) {
if (speakerRequest.isVerifyRequest()) {
service.handleAsyncResponse(dummyRequestKey, buildResponseOnVerifyRequest(speakerRequest));
} else {
service.handleAsyncResponse(dummyRequestKey, SpeakerFlowSegmentResponse.builder().messageContext(speakerRequest.getMessageContext()).commandId(speakerRequest.getCommandId()).metadata(speakerRequest.getMetadata()).switchId(speakerRequest.getSwitchId()).success(true).build());
}
}
Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
verifyNoPathReplace(origin, result);
}
use of org.openkilda.model.PathId in project open-kilda by telstra.
the class AvailableNetworkFactoryTest method shouldBuildAvailableNetworkForFlowWithIgnoreBandwidthPaths.
@Test
public void shouldBuildAvailableNetworkForFlowWithIgnoreBandwidthPaths() throws Exception {
Flow flow = getFlow(false);
IslImmutableView isl = getIslView(flow);
PathId pathId = new PathId("flow-path-id");
FlowPath flowPath = FlowPath.builder().pathId(pathId).srcSwitch(flow.getSrcSwitch()).destSwitch(flow.getDestSwitch()).ignoreBandwidth(true).build();
when(config.getNetworkStrategy()).thenReturn("SYMMETRIC_COST");
when(islRepository.findSymmetricActiveByBandwidthAndEncapsulationType(flow.getBandwidth(), flow.getEncapsulationType())).thenReturn(Collections.singletonList(isl));
when(flowPathRepository.findById(pathId)).thenReturn(Optional.of(flowPath));
AvailableNetwork availableNetwork = availableNetworkFactory.getAvailableNetwork(flow, Collections.singletonList(pathId));
assertAvailableNetworkIsCorrect(isl, availableNetwork);
}
use of org.openkilda.model.PathId in project open-kilda by telstra.
the class AvailableNetworkFactoryTest method shouldIncreaseDiversityGroupUseCounter.
@Test
public void shouldIncreaseDiversityGroupUseCounter() throws RecoverableException {
// Topology:
// A----B----C Already created flow: B-D
// | Requested flow: A-B-C
// D
// there is no ISL B-D because we assume that is has no enough bandwidth
List<IslImmutableView> isls = new ArrayList<>();
isls.addAll(getBidirectionalIsls(switchA, 1, switchB, 2));
isls.addAll(getBidirectionalIsls(switchB, 3, switchC, 4));
FlowPath forwardPath = FlowPath.builder().srcSwitch(switchB).destSwitch(switchD).pathId(FORWARD_PATH_ID).segments(Collections.singletonList(PathSegment.builder().pathId(FORWARD_PATH_ID).srcSwitch(switchB).srcPort(SRC_PORT).destSwitch(switchD).destPort(DEST_PORT).build())).build();
when(flowPathRepository.findById(FORWARD_PATH_ID)).thenReturn(java.util.Optional.of(forwardPath));
FlowPath reversePath = FlowPath.builder().srcSwitch(switchD).destSwitch(switchB).pathId(REVERSE_PATH_ID).segments(Collections.singletonList(PathSegment.builder().pathId(REVERSE_PATH_ID).srcSwitch(switchD).srcPort(DEST_PORT).destSwitch(switchB).destPort(SRC_PORT).build())).build();
when(flowPathRepository.findById(REVERSE_PATH_ID)).thenReturn(java.util.Optional.of(reversePath));
Flow flow = getFlow(false);
flow.setSrcSwitch(switchA);
flow.setDestSwitch(switchC);
flow.setDiverseGroupId(DIVERSE_GROUP_ID);
flow.setForwardPathId(new PathId("forward_path_id"));
flow.setReversePathId(new PathId("reverse_path_id"));
when(config.getNetworkStrategy()).thenReturn(BuildStrategy.COST.name());
when(islRepository.findActiveByBandwidthAndEncapsulationType(flow.getBandwidth(), flow.getEncapsulationType())).thenReturn(isls);
when(flowPathRepository.findPathIdsByFlowDiverseGroupId(DIVERSE_GROUP_ID)).thenReturn(Lists.newArrayList(FORWARD_PATH_ID, REVERSE_PATH_ID));
AvailableNetwork availableNetwork = availableNetworkFactory.getAvailableNetwork(flow, Collections.emptyList());
assertEquals(2, availableNetwork.getSwitch(switchB.getSwitchId()).getDiversityGroupUseCounter());
}
Aggregations