use of org.openkilda.messaging.command.reroute.RerouteAffectedFlows in project open-kilda by telstra.
the class RerouteServiceTest method shouldSkipRerouteRequestsForFlowWithoutAffectedPathSegment.
@Test
public void shouldSkipRerouteRequestsForFlowWithoutAffectedPathSegment() {
PathNode islSide = new PathNode(SWITCH_A.getSwitchId(), 1, 0);
FlowPathRepository pathRepository = mock(FlowPathRepository.class);
when(pathRepository.findBySegmentEndpoint(eq(islSide.getSwitchId()), eq(islSide.getPortNo()))).thenReturn(asList(regularFlow.getForwardPath(), regularFlow.getReversePath()));
FlowRepository flowRepository = mock(FlowRepository.class);
PathSegmentRepository pathSegmentRepository = mock(PathSegmentRepository.class);
doThrow(new EntityNotFoundException("Not found")).when(pathSegmentRepository).updateFailedStatus(any(), any(), anyBoolean());
RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
when(repositoryFactory.createPathSegmentRepository()).thenReturn(pathSegmentRepository);
when(repositoryFactory.createFlowPathRepository()).thenReturn(pathRepository);
when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository);
PersistenceManager persistenceManager = mock(PersistenceManager.class);
when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
when(persistenceManager.getTransactionManager()).thenReturn(transactionManager);
RerouteService rerouteService = new RerouteService(persistenceManager);
RerouteAffectedFlows request = new RerouteAffectedFlows(islSide, "dummy-reason - unittest");
rerouteService.rerouteAffectedFlows(carrier, CORRELATION_ID, request);
verifyZeroInteractions(carrier);
}
use of org.openkilda.messaging.command.reroute.RerouteAffectedFlows in project open-kilda by telstra.
the class RerouteServiceTest method handlePathNoFoundException.
@Test
public void handlePathNoFoundException() {
PathNode islSide = new PathNode(SWITCH_A.getSwitchId(), 1, 0);
FlowPathRepository pathRepository = mock(FlowPathRepository.class);
when(pathRepository.findBySegmentEndpoint(eq(islSide.getSwitchId()), eq(islSide.getPortNo()))).thenReturn(asList(regularFlow.getForwardPath(), regularFlow.getReversePath()));
FlowRepository flowRepository = mock(FlowRepository.class);
RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
when(repositoryFactory.createPathSegmentRepository()).thenReturn(mock(PathSegmentRepository.class));
when(repositoryFactory.createFlowPathRepository()).thenReturn(pathRepository);
when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository);
PersistenceManager persistenceManager = mock(PersistenceManager.class);
when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
when(persistenceManager.getTransactionManager()).thenReturn(transactionManager);
RerouteService rerouteService = new RerouteService(persistenceManager);
RerouteAffectedFlows request = new RerouteAffectedFlows(islSide, "dummy-reason - unittest");
rerouteService.rerouteAffectedFlows(carrier, CORRELATION_ID, request);
verify(flowRepository).updateStatusSafe(eq(regularFlow), eq(FlowStatus.DOWN), any());
FlowThrottlingData expected = FlowThrottlingData.builder().correlationId(CORRELATION_ID).priority(regularFlow.getPriority()).timeCreate(regularFlow.getTimeCreate()).affectedIsl(Collections.singleton(new IslEndpoint(islSide.getSwitchId(), islSide.getPortNo()))).force(false).effectivelyDown(true).reason(request.getReason()).build();
verify(carrier).emitRerouteCommand(eq(regularFlow.getFlowId()), eq(expected));
}
use of org.openkilda.messaging.command.reroute.RerouteAffectedFlows in project open-kilda by telstra.
the class NetworkIslServiceTest method continuousReplugVsRoundTripAlive.
@Test
public void continuousReplugVsRoundTripAlive() {
setupIslStorageStub();
IslReference referenceAlpha = prepareActiveIsl();
IslReference referenceBeta = new IslReference(Endpoint.of(referenceAlpha.getSource().getDatapath(), referenceAlpha.getSource().getPortNumber() + 1), referenceAlpha.getDest());
Instant lastSeen = clock.instant();
service.roundTripStatusNotification(referenceAlpha, new RoundTripStatus(referenceAlpha.getSource(), IslStatus.ACTIVE));
IslDataHolder alphaSource = new IslDataHolder(lookupIsl(referenceAlpha.getSource(), referenceAlpha.getDest()));
IslDataHolder alphaDest = new IslDataHolder(lookupIsl(referenceAlpha.getDest(), referenceAlpha.getSource()));
IslDataHolder betaSource = new IslDataHolder(makeIsl(referenceBeta.getSource(), referenceBeta.getDest(), false).build());
IslDataHolder betaDest = new IslDataHolder(makeIsl(referenceBeta.getDest(), referenceBeta.getSource(), false).build());
IslStatusUpdateNotification alphaNotification = new IslStatusUpdateNotification(referenceAlpha.getSource().getDatapath(), referenceAlpha.getSource().getPortNumber(), referenceAlpha.getDest().getDatapath(), referenceAlpha.getDest().getPortNumber(), IslStatus.MOVED);
IslStatusUpdateNotification betaNotification = new IslStatusUpdateNotification(referenceBeta.getSource().getDatapath(), referenceBeta.getSource().getPortNumber(), referenceBeta.getDest().getDatapath(), referenceBeta.getDest().getPortNumber(), IslStatus.MOVED);
for (int i = 0; i < 100; i++) {
// alpha -> beta
service.islMove(referenceAlpha.getSource(), referenceAlpha);
service.islUp(referenceBeta.getSource(), referenceBeta, betaSource);
service.islUp(referenceBeta.getDest(), referenceBeta, betaDest);
service.roundTripStatusNotification(referenceBeta, new RoundTripStatus(referenceBeta.getSource(), IslStatus.ACTIVE));
verifyStatus(referenceAlpha, IslStatus.MOVED);
verifyStatus(referenceBeta, IslStatus.ACTIVE);
verify(carrier, times(i + 1)).islStatusUpdateNotification(eq(alphaNotification));
verify(carrier, times(i + 1)).triggerReroute(argThat(entry -> entry instanceof RerouteAffectedFlows && Objects.equals(new PathNode(referenceAlpha.getSource().getDatapath(), referenceAlpha.getSource().getPortNumber(), 0), entry.getPathNode())));
verify(carrier, times(i + 1)).triggerReroute(argThat(entry -> entry instanceof RerouteInactiveFlows && Objects.equals(new PathNode(referenceBeta.getSource().getDatapath(), referenceBeta.getSource().getPortNumber(), 0), entry.getPathNode())));
// beta -> alpha
service.islMove(referenceBeta.getSource(), referenceBeta);
service.islUp(referenceAlpha.getSource(), referenceAlpha, alphaSource);
service.islUp(referenceAlpha.getDest(), referenceAlpha, alphaDest);
service.roundTripStatusNotification(referenceAlpha, new RoundTripStatus(referenceAlpha.getSource(), IslStatus.ACTIVE));
verifyStatus(referenceAlpha, IslStatus.ACTIVE);
verifyStatus(referenceBeta, IslStatus.MOVED);
verify(carrier, times(i + 1)).islStatusUpdateNotification(eq(betaNotification));
verify(carrier, times(i + 1)).triggerReroute(argThat(entry -> entry instanceof RerouteAffectedFlows && Objects.equals(new PathNode(referenceBeta.getSource().getDatapath(), referenceBeta.getSource().getPortNumber(), 0), entry.getPathNode())));
verify(carrier, times(i + 1)).triggerReroute(argThat(entry -> entry instanceof RerouteInactiveFlows && Objects.equals(new PathNode(referenceAlpha.getSource().getDatapath(), referenceAlpha.getSource().getPortNumber(), 0), entry.getPathNode())));
}
}
use of org.openkilda.messaging.command.reroute.RerouteAffectedFlows in project open-kilda by telstra.
the class RerouteBolt method handleCommandMessage.
private void handleCommandMessage(CommandMessage commandMessage) {
CommandData commandData = commandMessage.getData();
String correlationId = getCommandContext().getCorrelationId();
if (commandData instanceof RerouteAffectedFlows) {
rerouteService.rerouteAffectedFlows(this, correlationId, (RerouteAffectedFlows) commandData);
} else if (commandData instanceof RerouteAffectedInactiveFlows) {
rerouteService.rerouteInactiveAffectedFlows(this, correlationId, ((RerouteAffectedInactiveFlows) commandData).getSwitchId());
} else if (commandData instanceof RerouteInactiveFlows) {
rerouteService.rerouteInactiveFlows(this, correlationId, (RerouteInactiveFlows) commandData);
} else if (commandData instanceof FlowRerouteRequest) {
rerouteService.processRerouteRequest(this, correlationId, (FlowRerouteRequest) commandData);
} else if (commandData instanceof YFlowRerouteRequest) {
rerouteService.processRerouteRequest(this, correlationId, (YFlowRerouteRequest) commandData);
} else {
unhandledInput(getCurrentTuple());
}
}
use of org.openkilda.messaging.command.reroute.RerouteAffectedFlows in project open-kilda by telstra.
the class RerouteServiceTest method handlePathNoFoundExceptionForSubYFlow.
@Test
public void handlePathNoFoundExceptionForSubYFlow() {
PathNode islSide = new PathNode(SWITCH_A.getSwitchId(), 1, 0);
FlowPathRepository pathRepository = mock(FlowPathRepository.class);
when(pathRepository.findBySegmentEndpoint(eq(islSide.getSwitchId()), eq(islSide.getPortNo()))).thenReturn(asList(subFlow.getForwardPath(), subFlow.getReversePath()));
FlowRepository flowRepository = mock(FlowRepository.class);
YFlowRepository yFlowRepository = mock(YFlowRepository.class);
RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
when(repositoryFactory.createPathSegmentRepository()).thenReturn(mock(PathSegmentRepository.class));
when(repositoryFactory.createFlowPathRepository()).thenReturn(pathRepository);
when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository);
when(repositoryFactory.createYFlowRepository()).thenReturn(yFlowRepository);
PersistenceManager persistenceManager = mock(PersistenceManager.class);
when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
when(persistenceManager.getTransactionManager()).thenReturn(transactionManager);
RerouteService rerouteService = new RerouteService(persistenceManager);
RerouteAffectedFlows request = new RerouteAffectedFlows(islSide, "dummy-reason - unittest");
rerouteService.rerouteAffectedFlows(carrier, CORRELATION_ID, request);
verify(flowRepository).updateStatusSafe(eq(subFlow), eq(FlowStatus.DOWN), any());
FlowThrottlingData expected = FlowThrottlingData.builder().correlationId(CORRELATION_ID).priority(regularYFlow.getPriority()).timeCreate(regularYFlow.getTimeCreate()).affectedIsl(Collections.singleton(new IslEndpoint(islSide.getSwitchId(), islSide.getPortNo()))).force(false).effectivelyDown(true).reason(request.getReason()).yFlow(true).build();
verify(carrier).emitRerouteCommand(eq(regularYFlow.getYFlowId()), eq(expected));
}
Aggregations