Search in sources :

Example 6 with BfdSessionData

use of org.openkilda.wfm.topology.network.model.BfdSessionData in project open-kilda by telstra.

the class NetworkBfdLogicalPortServiceTest method replacePropertiesDuringCreate.

@Test
public void replacePropertiesDuringCreate() {
    NetworkBfdLogicalPortService service = makeService();
    switchOnlineStatusMonitor.update(physical.getDatapath(), true);
    final String requestId = "port-create-request";
    when(carrier.createLogicalPort(eq(logical), eq(physical.getPortNumber()))).thenReturn(requestId);
    service.apply(physical, reference, propertiesEnabled);
    reset(carrier);
    BfdProperties altProperties = new BfdProperties(Duration.ofMillis(propertiesEnabled.getInterval().toMillis() + 100), (short) (propertiesEnabled.getMultiplier() + 1));
    service.apply(physical, reference, altProperties);
    verify(carrier).createLogicalPort(eq(logical), eq(physical.getPortNumber()));
    verifyNoMoreInteractions(carrier);
    service.portAdd(logical, physical.getPortNumber());
    verify(carrier).enableUpdateSession(eq(logical), eq(physical.getPortNumber()), eq(new BfdSessionData(reference, altProperties)));
}
Also used : BfdSessionData(org.openkilda.wfm.topology.network.model.BfdSessionData) BfdProperties(org.openkilda.model.BfdProperties) Test(org.junit.Test)

Example 7 with BfdSessionData

use of org.openkilda.wfm.topology.network.model.BfdSessionData in project open-kilda by telstra.

the class NetworkBfdSessionServiceTest method surviveOffline.

@Test
public void surviveOffline() {
    // offline
    switchOnlineStatusMonitor.update(alphaLogicalEndpoint.getDatapath(), false);
    doAnswer(invocation -> invocation.getArgument(0)).when(bfdSessionRepository).add(any());
    mockSwitchLookup(alphaSwitch);
    mockSwitchLookup(betaSwitch);
    mockMissingBfdSession(alphaLogicalEndpoint);
    service.enableUpdate(alphaLogicalEndpoint, alphaEndpoint.getPortNumber(), new BfdSessionData(alphaToBetaIslRef, genericBfdProperties));
    verifyNoMoreInteractions(carrier);
    // online
    switchOnlineStatusMonitor.update(alphaLogicalEndpoint.getDatapath(), true);
    // ensure we react on enable requests
    verify(carrier).sendWorkerBfdSessionCreateRequest(argThat(argument -> argument.getTarget().getDatapath().equals(alphaLogicalEndpoint.getDatapath()) && argument.getRemote().getDatapath().equals(betaEndpoint.getDatapath())));
    verifyNoMoreInteractions(carrier);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BfdProperties(org.openkilda.model.BfdProperties) TransactionManager(org.openkilda.persistence.tx.TransactionManager) BfdSessionRepository(org.openkilda.persistence.repositories.BfdSessionRepository) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) EndpointStatusMonitor(org.openkilda.wfm.topology.network.utils.EndpointStatusMonitor) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) BfdSession(org.openkilda.model.BfdSession) IslReference(org.openkilda.wfm.share.model.IslReference) InetAddress(java.net.InetAddress) ArgumentCaptor(org.mockito.ArgumentCaptor) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Duration(java.time.Duration) PersistenceManager(org.openkilda.persistence.PersistenceManager) LinkStatus(org.openkilda.wfm.topology.network.model.LinkStatus) Before(org.junit.Before) IpSocketAddress(org.openkilda.model.IpSocketAddress) Switch(org.openkilda.model.Switch) TransactionCallback(org.openkilda.persistence.tx.TransactionCallback) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Endpoint(org.openkilda.wfm.share.model.Endpoint) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) UnknownHostException(java.net.UnknownHostException) Mockito.verify(org.mockito.Mockito.verify) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) Mockito(org.mockito.Mockito) NoviBfdSession(org.openkilda.messaging.model.NoviBfdSession) BfdSessionData(org.openkilda.wfm.topology.network.model.BfdSessionData) SwitchId(org.openkilda.model.SwitchId) SwitchOnlineStatusMonitor(org.openkilda.wfm.topology.network.utils.SwitchOnlineStatusMonitor) BfdSessionResponse(org.openkilda.messaging.floodlight.response.BfdSessionResponse) Optional(java.util.Optional) TransactionCallbackWithoutResult(org.openkilda.persistence.tx.TransactionCallbackWithoutResult) Assert(org.junit.Assert) Mockito.reset(org.mockito.Mockito.reset) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) BfdSessionData(org.openkilda.wfm.topology.network.model.BfdSessionData) Test(org.junit.Test)

Example 8 with BfdSessionData

use of org.openkilda.wfm.topology.network.model.BfdSessionData 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 9 with BfdSessionData

use of org.openkilda.wfm.topology.network.model.BfdSessionData 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 10 with BfdSessionData

use of org.openkilda.wfm.topology.network.model.BfdSessionData in project open-kilda by telstra.

the class NetworkBfdSessionServiceTest method enableForAllocatedDiscriminatorByNotCreatedSession.

@Test
public void enableForAllocatedDiscriminatorByNotCreatedSession() {
    BfdSession prehistory = makeBfdSessionBuilder(1).interval(null).multiplier((short) 0).build();
    mockBfdSessionLookup(prehistory);
    mockSwitchLookup(alphaSwitch);
    mockSwitchLookup(betaSwitch);
    switchOnlineStatusMonitor.update(prehistory.getSwitchId(), true);
    when(carrier.sendWorkerBfdSessionCreateRequest(any(NoviBfdSession.class))).thenReturn(setupRequestKey);
    service.enableUpdate(Endpoint.of(prehistory.getSwitchId(), prehistory.getPort()), prehistory.getPhysicalPort(), new BfdSessionData(alphaToBetaIslRef, genericBfdProperties));
    verify(carrier).sendWorkerBfdSessionCreateRequest(any(NoviBfdSession.class));
    verifyNoMoreInteractions(carrier);
}
Also used : BfdSessionData(org.openkilda.wfm.topology.network.model.BfdSessionData) BfdSession(org.openkilda.model.BfdSession) NoviBfdSession(org.openkilda.messaging.model.NoviBfdSession) NoviBfdSession(org.openkilda.messaging.model.NoviBfdSession) Test(org.junit.Test)

Aggregations

BfdSessionData (org.openkilda.wfm.topology.network.model.BfdSessionData)12 Test (org.junit.Test)9 NoviBfdSession (org.openkilda.messaging.model.NoviBfdSession)7 BfdSession (org.openkilda.model.BfdSession)6 BfdSessionResponse (org.openkilda.messaging.floodlight.response.BfdSessionResponse)5 BfdProperties (org.openkilda.model.BfdProperties)4 DeleteLogicalPortResponse (org.openkilda.messaging.info.grpc.DeleteLogicalPortResponse)2 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 Duration (java.time.Duration)1 Optional (java.util.Optional)1 Assert (org.junit.Assert)1 Before (org.junit.Before)1 RunWith (org.junit.runner.RunWith)1 ArgumentCaptor (org.mockito.ArgumentCaptor)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)1 Mock (org.mockito.Mock)1 Mockito (org.mockito.Mockito)1 Mockito.atLeastOnce (org.mockito.Mockito.atLeastOnce)1