Search in sources :

Example 6 with NoviBfdSession

use of org.openkilda.messaging.model.NoviBfdSession in project open-kilda by telstra.

the class NetworkBfdSessionServiceTest method forceCleanupAfterInit.

private NoviBfdSession forceCleanupAfterInit(BfdSession initialBfdSession) {
    switchOnlineStatusMonitor.update(alphaLogicalEndpoint.getDatapath(), true);
    when(bfdSessionRepository.findBySwitchIdAndPort(alphaLogicalEndpoint.getDatapath(), alphaLogicalEndpoint.getPortNumber())).thenReturn(Optional.of(initialBfdSession));
    mockSwitchLookup(alphaSwitch);
    mockSwitchLookup(betaSwitch);
    when(carrier.sendWorkerBfdSessionDeleteRequest(any(NoviBfdSession.class))).thenReturn(removeRequestKey);
    service.enableUpdate(alphaLogicalEndpoint, alphaEndpoint.getPortNumber(), new BfdSessionData(alphaToBetaIslRef, genericBfdProperties));
    ArgumentCaptor<NoviBfdSession> setupBfdSessionArgument = ArgumentCaptor.forClass(NoviBfdSession.class);
    verify(carrier).sendWorkerBfdSessionDeleteRequest(setupBfdSessionArgument.capture());
    resetCarrier();
    reset(bfdSessionRepository);
    return setupBfdSessionArgument.getValue();
}
Also used : BfdSessionData(org.openkilda.wfm.topology.network.model.BfdSessionData) NoviBfdSession(org.openkilda.messaging.model.NoviBfdSession)

Example 7 with NoviBfdSession

use of org.openkilda.messaging.model.NoviBfdSession in project open-kilda by telstra.

the class NetworkBfdSessionServiceTest method enableEnable.

@Test
public void enableEnable() {
    createOperationalSession();
    // active
    when(carrier.sendWorkerBfdSessionDeleteRequest(any(NoviBfdSession.class))).thenReturn(removeRequestKey);
    BfdProperties update = BfdProperties.builder().interval(Duration.ofMillis(genericBfdProperties.getInterval().toMillis() + 100)).multiplier((short) (genericBfdProperties.getMultiplier() + 1)).build();
    service.enableUpdate(alphaLogicalEndpoint, alphaEndpoint.getPortNumber(), new BfdSessionData(alphaToBetaIslRef, update));
    verify(carrier).bfdKillNotification(alphaEndpoint);
    ArgumentCaptor<NoviBfdSession> speakerBfdRequestArgument = ArgumentCaptor.forClass(NoviBfdSession.class);
    verify(carrier).sendWorkerBfdSessionDeleteRequest(speakerBfdRequestArgument.capture());
    NoviBfdSession speakerBfdSession = speakerBfdRequestArgument.getValue();
    verifyNoMoreInteractions(carrier);
    resetCarrier();
    // reset
    mockMissingBfdSession(alphaLogicalEndpoint);
    when(carrier.sendWorkerBfdSessionCreateRequest(any(NoviBfdSession.class))).thenReturn(setupRequestKey);
    BfdSessionResponse removeResponse = new BfdSessionResponse(speakerBfdSession, null);
    service.speakerResponse(alphaLogicalEndpoint, removeRequestKey, removeResponse);
    verify(carrier).sendWorkerBfdSessionCreateRequest(speakerBfdRequestArgument.capture());
    speakerBfdSession = speakerBfdRequestArgument.getValue();
    Assert.assertEquals(update.getInterval().toMillis(), speakerBfdSession.getIntervalMs());
    Assert.assertEquals(update.getMultiplier(), speakerBfdSession.getMultiplier());
    verify(carrier).sessionRotateRequest(alphaLogicalEndpoint, false);
    verifyNoMoreInteractions(carrier);
    resetCarrier();
    reset(bfdSessionRepository);
    // do_setup
    BfdSession dbView = BfdSession.builder().switchId(alphaLogicalEndpoint.getDatapath()).port(alphaLogicalEndpoint.getPortNumber()).physicalPort(alphaEndpoint.getPortNumber()).interval(genericBfdProperties.getInterval()).multiplier(genericBfdProperties.getMultiplier()).build();
    when(bfdSessionRepository.findBySwitchIdAndPort(alphaLogicalEndpoint.getDatapath(), alphaLogicalEndpoint.getPortNumber())).thenReturn(Optional.of(dbView));
    BfdSessionResponse setupResponse = new BfdSessionResponse(speakerBfdSession, null);
    service.speakerResponse(alphaLogicalEndpoint, setupRequestKey, setupResponse);
    endpointStatusMonitor.update(alphaLogicalEndpoint, LinkStatus.UP);
    verify(carrier).bfdUpNotification(alphaEndpoint);
    verifyNoMoreInteractions(carrier);
    resetCarrier();
    Assert.assertEquals(update.getInterval(), dbView.getInterval());
    Assert.assertEquals(update.getMultiplier(), BfdProperties.normalizeMultiplier(dbView.getMultiplier()));
    // active
    // ensure we are reaction on link status update
    endpointStatusMonitor.update(alphaLogicalEndpoint, LinkStatus.DOWN);
    verify(carrier).bfdDownNotification(alphaEndpoint);
}
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) BfdProperties(org.openkilda.model.BfdProperties) NoviBfdSession(org.openkilda.messaging.model.NoviBfdSession) Test(org.junit.Test)

Example 8 with NoviBfdSession

use of org.openkilda.messaging.model.NoviBfdSession in project open-kilda by telstra.

the class NetworkBfdSessionServiceTest method enableDisable.

@Test
public void enableDisable() throws UnknownHostException {
    when(bfdSessionRepository.findBySwitchIdAndPort(alphaLogicalEndpoint.getDatapath(), alphaLogicalEndpoint.getPortNumber())).thenReturn(Optional.empty());
    mockSwitchLookup(alphaSwitch);
    mockSwitchLookup(betaSwitch);
    doAnswer(invocation -> invocation.getArgument(0)).when(bfdSessionRepository).add(any());
    // handle enable/update request
    when(carrier.sendWorkerBfdSessionCreateRequest(any(NoviBfdSession.class))).thenReturn(setupRequestKey);
    switchOnlineStatusMonitor.update(alphaEndpoint.getDatapath(), true);
    service.enableUpdate(alphaLogicalEndpoint, alphaEndpoint.getPortNumber(), new BfdSessionData(alphaToBetaIslRef, genericBfdProperties));
    ArgumentCaptor<NoviBfdSession> createBfdSessionRequestCaptor = ArgumentCaptor.forClass(NoviBfdSession.class);
    verify(carrier).sendWorkerBfdSessionCreateRequest(createBfdSessionRequestCaptor.capture());
    NoviBfdSession setupBfdSessionPayload = createBfdSessionRequestCaptor.getValue();
    ArgumentCaptor<BfdSession> bfdSessionCreateArgument = ArgumentCaptor.forClass(BfdSession.class);
    verify(bfdSessionRepository).add(bfdSessionCreateArgument.capture());
    BfdSession bfdSessionDb = bfdSessionCreateArgument.getValue();
    Assert.assertNotNull(bfdSessionDb.getDiscriminator());
    Assert.assertNull(bfdSessionDb.getInterval());
    Assert.assertEquals(Short.valueOf((short) 0), bfdSessionDb.getMultiplier());
    // speaker response
    when(bfdSessionRepository.findBySwitchIdAndPort(alphaLogicalEndpoint.getDatapath(), alphaLogicalEndpoint.getPortNumber())).thenReturn(Optional.of(bfdSessionCreateArgument.getValue()));
    service.speakerResponse(alphaLogicalEndpoint, setupRequestKey, new BfdSessionResponse(setupBfdSessionPayload, null));
    endpointStatusMonitor.update(alphaLogicalEndpoint, LinkStatus.UP);
    verify(bfdSessionRepository).add(bfdSessionCreateArgument.capture());
    bfdSessionDb = bfdSessionCreateArgument.getValue();
    Assert.assertEquals(alphaLogicalEndpoint.getDatapath(), bfdSessionDb.getSwitchId());
    Assert.assertEquals((Integer) alphaLogicalEndpoint.getPortNumber(), bfdSessionDb.getPort());
    Assert.assertNotNull(bfdSessionDb.getDiscriminator());
    ArgumentCaptor<NoviBfdSession> bfdSessionCreateSpeakerArgument = ArgumentCaptor.forClass(NoviBfdSession.class);
    verify(carrier).sendWorkerBfdSessionCreateRequest(bfdSessionCreateSpeakerArgument.capture());
    NoviBfdSession speakerBfdSetup = bfdSessionCreateSpeakerArgument.getValue();
    Assert.assertEquals(alphaEndpoint.getDatapath(), speakerBfdSetup.getTarget().getDatapath());
    Assert.assertEquals(InetAddress.getByName(alphaAddress), speakerBfdSetup.getTarget().getInetAddress());
    Assert.assertEquals(betaEndpoint.getDatapath(), speakerBfdSetup.getRemote().getDatapath());
    Assert.assertEquals(InetAddress.getByName(betaAddress), speakerBfdSetup.getRemote().getInetAddress());
    Assert.assertEquals(alphaEndpoint.getPortNumber(), speakerBfdSetup.getPhysicalPortNumber());
    Assert.assertEquals(alphaLogicalEndpoint.getPortNumber(), speakerBfdSetup.getLogicalPortNumber());
    Assert.assertEquals(bfdSessionDb.getDiscriminator(), (Integer) speakerBfdSetup.getDiscriminator());
    Assert.assertEquals(genericBfdProperties.getInterval(), bfdSessionDb.getInterval());
    Assert.assertEquals(Short.valueOf(genericBfdProperties.getMultiplier()), bfdSessionDb.getMultiplier());
    Assert.assertTrue(speakerBfdSetup.isKeepOverDisconnect());
    verify(carrier).bfdUpNotification(alphaEndpoint);
    verifyNoMoreInteractions(carrier);
    resetCarrier();
    reset(bfdSessionRepository);
    // remove BFD session
    when(carrier.sendWorkerBfdSessionDeleteRequest(any(NoviBfdSession.class))).thenReturn(removeRequestKey);
    service.disable(alphaEndpoint);
    verify(carrier).bfdKillNotification(alphaEndpoint);
    ArgumentCaptor<NoviBfdSession> bfdSessionRemoveSpeakerArgument = ArgumentCaptor.forClass(NoviBfdSession.class);
    verify(carrier).sendWorkerBfdSessionDeleteRequest(bfdSessionRemoveSpeakerArgument.capture());
    NoviBfdSession speakerBfdRemove = bfdSessionRemoveSpeakerArgument.getValue();
    Assert.assertEquals(speakerBfdSetup, speakerBfdRemove);
    verifyNoMoreInteractions(carrier);
    verifyNoMoreInteractions(bfdSessionRepository);
    resetCarrier();
    // remove confirmation
    when(bfdSessionRepository.findBySwitchIdAndPort(alphaLogicalEndpoint.getDatapath(), alphaLogicalEndpoint.getPortNumber())).thenReturn(Optional.of(bfdSessionDb));
    BfdSessionResponse speakerResponse = new BfdSessionResponse(speakerBfdRemove, null);
    service.speakerResponse(alphaLogicalEndpoint, removeRequestKey, speakerResponse);
    verify(carrier).sessionRotateRequest(alphaLogicalEndpoint, false);
    verify(carrier).sessionCompleteNotification(alphaEndpoint);
    verify(bfdSessionRepository).findBySwitchIdAndPort(alphaLogicalEndpoint.getDatapath(), alphaLogicalEndpoint.getPortNumber());
    verify(bfdSessionRepository).remove(bfdSessionDb);
    verifyNoMoreInteractions(carrier);
    verifyNoMoreInteractions(bfdSessionRepository);
}
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 9 with NoviBfdSession

use of org.openkilda.messaging.model.NoviBfdSession in project open-kilda by telstra.

the class NetworkBfdSessionServiceTest method createOperationalSession.

private NoviBfdSession createOperationalSession() {
    switchOnlineStatusMonitor.update(alphaLogicalEndpoint.getDatapath(), true);
    doAnswer(invocation -> invocation.getArgument(0)).when(bfdSessionRepository).add(any());
    mockSwitchLookup(alphaSwitch);
    mockSwitchLookup(betaSwitch);
    mockMissingBfdSession(alphaLogicalEndpoint);
    when(carrier.sendWorkerBfdSessionCreateRequest(any(NoviBfdSession.class))).thenReturn(setupRequestKey);
    service.enableUpdate(alphaLogicalEndpoint, alphaEndpoint.getPortNumber(), new BfdSessionData(alphaToBetaIslRef, genericBfdProperties));
    ArgumentCaptor<NoviBfdSession> speakerBfdSetupRequestArgument = ArgumentCaptor.forClass(NoviBfdSession.class);
    verify(carrier).sendWorkerBfdSessionCreateRequest(speakerBfdSetupRequestArgument.capture());
    NoviBfdSession speakerBfdSession = speakerBfdSetupRequestArgument.getValue();
    verify(bfdSessionRepository).add(any(BfdSession.class));
    resetCarrier();
    reset(bfdSessionRepository);
    // speaker response
    BfdSessionResponse response = new BfdSessionResponse(speakerBfdSession, null);
    service.speakerResponse(alphaLogicalEndpoint, setupRequestKey, response);
    verifyNoMoreInteractions(carrier);
    resetCarrier();
    // port up
    endpointStatusMonitor.update(alphaLogicalEndpoint, LinkStatus.UP);
    verify(carrier).bfdUpNotification(alphaEndpoint);
    verifyNoMoreInteractions(carrier);
    resetCarrier();
    return speakerBfdSession;
}
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)

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