Search in sources :

Example 1 with NoviBfdSession

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));
    }
}
Also used : NoviBfdSession(org.openkilda.messaging.model.NoviBfdSession)

Example 2 with NoviBfdSession

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");
}
Also used : IOFSwitch(net.floodlightcontroller.core.IOFSwitch) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) MessageError(org.openkilda.messaging.error.MessageError) DatapathId(org.projectfloodlight.openflow.types.DatapathId) IOException(java.io.IOException) SwitchNotFoundException(org.openkilda.floodlight.error.SwitchNotFoundException) NoviBfdSession(org.openkilda.messaging.model.NoviBfdSession) OFPacketOut(org.projectfloodlight.openflow.protocol.OFPacketOut) Post(org.restlet.resource.Post) Put(org.restlet.resource.Put)

Example 3 with NoviBfdSession

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);
}
Also used : BfdSession(org.openkilda.model.BfdSession) NoviBfdSession(org.openkilda.messaging.model.NoviBfdSession) BfdSessionResponse(org.openkilda.messaging.floodlight.response.BfdSessionResponse) NoviBfdSession(org.openkilda.messaging.model.NoviBfdSession) Test(org.junit.Test)

Example 4 with NoviBfdSession

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);
}
Also used : BfdSessionData(org.openkilda.wfm.topology.network.model.BfdSessionData) BfdSession(org.openkilda.model.BfdSession) NoviBfdSession(org.openkilda.messaging.model.NoviBfdSession) BfdSessionResponse(org.openkilda.messaging.floodlight.response.BfdSessionResponse) NoviBfdSession(org.openkilda.messaging.model.NoviBfdSession) Test(org.junit.Test)

Example 5 with NoviBfdSession

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);
}
Also used : BfdSessionResponse(org.openkilda.messaging.floodlight.response.BfdSessionResponse) NoviBfdSession(org.openkilda.messaging.model.NoviBfdSession) Test(org.junit.Test)

Aggregations

NoviBfdSession (org.openkilda.messaging.model.NoviBfdSession)9 BfdSessionResponse (org.openkilda.messaging.floodlight.response.BfdSessionResponse)6 Test (org.junit.Test)5 BfdSession (org.openkilda.model.BfdSession)5 BfdSessionData (org.openkilda.wfm.topology.network.model.BfdSessionData)5 IOException (java.io.IOException)1 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)1 SwitchNotFoundException (org.openkilda.floodlight.error.SwitchNotFoundException)1 ISwitchManager (org.openkilda.floodlight.switchmanager.ISwitchManager)1 MessageError (org.openkilda.messaging.error.MessageError)1 BfdProperties (org.openkilda.model.BfdProperties)1 OFPacketOut (org.projectfloodlight.openflow.protocol.OFPacketOut)1 DatapathId (org.projectfloodlight.openflow.types.DatapathId)1 Post (org.restlet.resource.Post)1 Put (org.restlet.resource.Put)1