use of org.openkilda.messaging.model.NoviBfdSession in project open-kilda by telstra.
the class SetupBfdSessionCommand method validate.
@Override
protected void validate(IOFSwitch sw) throws NoFeatureException {
super.validate(sw);
NoviBfdSession bfdSession = getBfdSession();
if (bfdSession.getIntervalMs() < CONSTRAINT_INTERVAL_MIN) {
throw new IllegalArgumentException(String.format("Invalid bfd session interval value: %d < %d", bfdSession.getIntervalMs(), CONSTRAINT_INTERVAL_MIN));
}
}
use of org.openkilda.messaging.model.NoviBfdSession in project open-kilda by telstra.
the class EnableBfdResource method enableBfd.
/**
* Setting up BFD session.
*
* @param json the json from request.
* @return json response.
* @throws JsonProcessingException if response can't be wrote to string.
*/
@Post("json")
@Put("json")
public String enableBfd(String json) {
ISwitchManager switchManager = (ISwitchManager) getContext().getAttributes().get(ISwitchManager.class.getCanonicalName());
NoviBfdSession request;
try {
request = MAPPER.readValue(json, NoviBfdSession.class);
if (request.getIntervalMs() < CONSTRAINT_INTERVAL_MIN) {
throw new IllegalArgumentException(String.format("Invalid bfd session interval value: %d < %d", request.getIntervalMs(), CONSTRAINT_INTERVAL_MIN));
}
DatapathId datapathIdtarget = DatapathId.of(request.getTarget().getDatapath().toLong());
IOFSwitch iofSwitch = switchManager.lookupSwitch(datapathIdtarget);
OFPacketOut outPacket = makeSessionConfigMessage(request, iofSwitch, switchManager);
if (!iofSwitch.write(outPacket)) {
throw new IllegalStateException("Failed to set up BFD session");
}
} catch (IOException e) {
logger.error("Message received is not valid BFD Request: {}", json);
MessageError responseMessage = new MessageError(DEFAULT_CORRELATION_ID, now(), ErrorType.DATA_INVALID.toString(), "Message received is not valid BFD Request", e.getMessage());
return generateJson(responseMessage);
} catch (SwitchNotFoundException e) {
MessageError responseMessage = new MessageError(DEFAULT_CORRELATION_ID, now(), ErrorType.DATA_INVALID.toString(), "Switch not found", e.getMessage());
return generateJson(responseMessage);
}
return generateJson("ok");
}
use of org.openkilda.messaging.model.NoviBfdSession in project open-kilda by telstra.
the class NetworkBfdSessionServiceTest method distinguishRecoverableErrors.
@Test
public void distinguishRecoverableErrors() {
// prepare DB record to force cleanup on start
BfdSession initialBfdSession = makeBfdSession(1);
NoviBfdSession removeRequestPayload = forceCleanupAfterInit(initialBfdSession);
// push speaker error response
when(bfdSessionRepository.findBySwitchIdAndPort(initialBfdSession.getSwitchId(), initialBfdSession.getPort())).thenReturn(Optional.of(initialBfdSession)).thenReturn(Optional.empty());
doAnswer(invocation -> invocation.getArgument(0)).when(bfdSessionRepository).add(any());
BfdSessionResponse removeResponse = new BfdSessionResponse(removeRequestPayload, NoviBfdSession.Errors.NOVI_BFD_DISCRIMINATOR_NOT_FOUND_ERROR);
// complete cleanup and make session create request
service.speakerResponse(alphaLogicalEndpoint, removeRequestKey, removeResponse);
verify(bfdSessionRepository, atLeastOnce()).findBySwitchIdAndPort(alphaLogicalEndpoint.getDatapath(), alphaLogicalEndpoint.getPortNumber());
verify(bfdSessionRepository).remove(initialBfdSession);
verify(bfdSessionRepository).add(any(BfdSession.class));
verify(carrier).sessionRotateRequest(alphaLogicalEndpoint, false);
verify(carrier).sendWorkerBfdSessionCreateRequest(any(NoviBfdSession.class));
verifyNoMoreInteractions(carrier);
verifyNoMoreInteractions(bfdSessionRepository);
}
use of org.openkilda.messaging.model.NoviBfdSession in project open-kilda by telstra.
the class NetworkBfdSessionServiceTest method failOnCriticalErrors.
@Test
public void failOnCriticalErrors() {
BfdSession initialBfdSession = makeBfdSession(1);
NoviBfdSession removeRequestPayload = forceCleanupAfterInit(initialBfdSession);
// push speaker error(critical) response
mockBfdSessionLookup(initialBfdSession);
BfdSessionResponse removeResponse = new BfdSessionResponse(removeRequestPayload, NoviBfdSession.Errors.SWITCH_RESPONSE_ERROR);
service.speakerResponse(alphaLogicalEndpoint, removeRequestKey, removeResponse);
verify(carrier).bfdFailNotification(alphaEndpoint);
verifyNoMoreInteractions(carrier);
verifyNoMoreInteractions(bfdSessionRepository);
resetCarrier();
reset(bfdSessionRepository);
// make one more remove attempt on next enable/update request
service.enableUpdate(alphaLogicalEndpoint, alphaEndpoint.getPortNumber(), new BfdSessionData(alphaToBetaIslRef, genericBfdProperties));
verify(carrier).sendWorkerBfdSessionDeleteRequest(removeRequestPayload);
verifyNoMoreInteractions(carrier);
}
use of org.openkilda.messaging.model.NoviBfdSession in project open-kilda by telstra.
the class NetworkBfdSessionServiceTest method offlineDuringCleaning.
@Test
public void offlineDuringCleaning() {
createOperationalSession();
String requestKey = "request-key-#";
// disable
when(carrier.sendWorkerBfdSessionDeleteRequest(any(NoviBfdSession.class))).thenReturn(requestKey + "1");
service.disable(alphaEndpoint);
ArgumentCaptor<NoviBfdSession> removeBfdSessionArgument = ArgumentCaptor.forClass(NoviBfdSession.class);
verify(carrier).sendWorkerBfdSessionDeleteRequest(removeBfdSessionArgument.capture());
resetCarrier();
// offline
switchOnlineStatusMonitor.update(alphaLogicalEndpoint.getDatapath(), false);
verifyNoMoreInteractions(carrier);
resetCarrier();
// online
when(carrier.sendWorkerBfdSessionDeleteRequest(any(NoviBfdSession.class))).thenReturn(requestKey + "2");
switchOnlineStatusMonitor.update(alphaLogicalEndpoint.getDatapath(), true);
endpointStatusMonitor.update(alphaLogicalEndpoint, LinkStatus.DOWN);
verify(carrier).sendWorkerBfdSessionDeleteRequest(removeBfdSessionArgument.getValue());
verifyNoMoreInteractions(carrier);
// ignore outdated timeout
service.speakerTimeout(alphaLogicalEndpoint, requestKey + "1");
verifyNoMoreInteractions(carrier);
service.speakerResponse(alphaLogicalEndpoint, requestKey + "2", new BfdSessionResponse(removeBfdSessionArgument.getValue(), NoviBfdSession.Errors.NOVI_BFD_DISCRIMINATOR_NOT_FOUND_ERROR));
verify(carrier).sessionRotateRequest(alphaLogicalEndpoint, false);
verify(carrier).sessionCompleteNotification(alphaEndpoint);
verifyNoMoreInteractions(carrier);
}
Aggregations