Search in sources :

Example 1 with BfdPropertiesResponse

use of org.openkilda.messaging.nbtopology.response.BfdPropertiesResponse in project open-kilda by telstra.

the class LinkServiceImpl method unpackBfdPropertiesResponse.

private BfdPropertiesResponse unpackBfdPropertiesResponse(List<InfoData> responseStream, CommandData request, String correlationId) {
    InfoData response = ensureExactlyOneResponse(responseStream, request, correlationId);
    if (response instanceof BfdPropertiesResponse) {
        return (BfdPropertiesResponse) response;
    }
    String description = String.format("Got %s response type, while expecting %s", response.getClass().getName(), BfdPropertiesResponse.class.getName());
    throw new MessageException(correlationId, System.currentTimeMillis(), ErrorType.INTERNAL_ERROR, "Unexpected inter component response type/format", description);
}
Also used : BfdPropertiesResponse(org.openkilda.messaging.nbtopology.response.BfdPropertiesResponse) MessageException(org.openkilda.messaging.error.MessageException) InfoData(org.openkilda.messaging.info.InfoData) IslInfoData(org.openkilda.messaging.info.event.IslInfoData)

Example 2 with BfdPropertiesResponse

use of org.openkilda.messaging.nbtopology.response.BfdPropertiesResponse in project open-kilda by telstra.

the class LinkServiceTest method writeBfdPropertiesHappyPath.

@Test
public void writeBfdPropertiesHappyPath() throws ExecutionException, InterruptedException {
    String correlationId = "bfd-properties-write-happy-path";
    NetworkEndpoint source = new NetworkEndpoint(new SwitchId(1), 1);
    NetworkEndpoint destination = new NetworkEndpoint(new SwitchId(2), 2);
    BfdProperties goal = new BfdProperties(350L, (short) 3);
    IslInfoData leftToRight = new IslInfoData(new PathNode(source.getDatapath(), source.getPortNumber(), 0), new PathNode(destination.getDatapath(), destination.getPortNumber(), 1), IslChangeType.DISCOVERED, false);
    IslInfoData rightToLeft = new IslInfoData(new PathNode(destination.getDatapath(), destination.getPortNumber(), 1), new PathNode(source.getDatapath(), source.getPortNumber(), 0), IslChangeType.DISCOVERED, false);
    messageExchanger.mockChunkedResponse(correlationId, Collections.singletonList(new BfdPropertiesResponse(source, destination, linkMapper.map(goal), new EffectiveBfdProperties(linkMapper.map(BfdProperties.DISABLED), null), new EffectiveBfdProperties(linkMapper.map(BfdProperties.DISABLED), null), leftToRight, rightToLeft)));
    RequestCorrelationId.create(correlationId);
    // make write request and schedule read request
    CompletableFuture<BfdPropertiesPayload> future = linkService.writeBfdProperties(source, destination, goal);
    Assert.assertFalse(future.isDone());
    ArgumentCaptor<Runnable> monitorTaskCaptor = ArgumentCaptor.forClass(Runnable.class);
    verify(taskScheduler).schedule(monitorTaskCaptor.capture(), any(Date.class));
    messageExchanger.mockChunkedResponse(makeBfdMonitorCorrelationId(correlationId, 0), Collections.singletonList(new BfdPropertiesResponse(source, destination, linkMapper.map(goal), new EffectiveBfdProperties(linkMapper.map(goal), null), new EffectiveBfdProperties(linkMapper.map(goal), null), leftToRight, rightToLeft)));
    // make read request
    monitorTaskCaptor.getValue().run();
    Assert.assertTrue(future.isDone());
    BfdPropertiesPayload result = future.get();
    Assert.assertEquals(goal, result.getProperties());
    Assert.assertEquals(goal, result.getEffectiveSource().getProperties());
    Assert.assertEquals(goal, result.getEffectiveDestination().getProperties());
}
Also used : NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) SwitchId(org.openkilda.model.SwitchId) PathNode(org.openkilda.messaging.info.event.PathNode) BfdPropertiesPayload(org.openkilda.northbound.dto.v2.links.BfdPropertiesPayload) Date(java.util.Date) BfdPropertiesResponse(org.openkilda.messaging.nbtopology.response.BfdPropertiesResponse) BfdProperties(org.openkilda.northbound.dto.v2.links.BfdProperties) EffectiveBfdProperties(org.openkilda.model.EffectiveBfdProperties) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) EffectiveBfdProperties(org.openkilda.model.EffectiveBfdProperties) Test(org.junit.Test)

Example 3 with BfdPropertiesResponse

use of org.openkilda.messaging.nbtopology.response.BfdPropertiesResponse in project open-kilda by telstra.

the class LinkServiceTest method writeBfdPropertiesApplyFail.

@Test
public void writeBfdPropertiesApplyFail() throws InterruptedException {
    String correlationId = "bfd-properties-write-apply-fail";
    NetworkEndpoint source = new NetworkEndpoint(new SwitchId(1), 1);
    NetworkEndpoint destination = new NetworkEndpoint(new SwitchId(2), 2);
    BfdProperties goal = new BfdProperties(350L, (short) 3);
    IslInfoData leftToRight = new IslInfoData(new PathNode(source.getDatapath(), source.getPortNumber(), 0), new PathNode(destination.getDatapath(), destination.getPortNumber(), 1), IslChangeType.DISCOVERED, false);
    IslInfoData rightToLeft = new IslInfoData(new PathNode(destination.getDatapath(), destination.getPortNumber(), 1), new PathNode(source.getDatapath(), source.getPortNumber(), 0), IslChangeType.DISCOVERED, false);
    messageExchanger.mockChunkedResponse(correlationId, Collections.singletonList(new BfdPropertiesResponse(source, destination, linkMapper.map(goal), new EffectiveBfdProperties(linkMapper.map(BfdProperties.DISABLED), null), new EffectiveBfdProperties(linkMapper.map(BfdProperties.DISABLED), null), leftToRight, rightToLeft)));
    RequestCorrelationId.create(correlationId);
    // make write request and schedule read request
    CompletableFuture<BfdPropertiesPayload> future = linkService.writeBfdProperties(source, destination, goal);
    Assert.assertFalse(future.isDone());
    ArgumentCaptor<Runnable> monitorTaskCaptor = ArgumentCaptor.forClass(Runnable.class);
    verify(taskScheduler).schedule(monitorTaskCaptor.capture(), any(Date.class));
    Mockito.reset(taskScheduler);
    clock.adjust(Duration.ofSeconds(1));
    messageExchanger.mockChunkedResponse(makeBfdMonitorCorrelationId(correlationId, 0), Collections.singletonList(new BfdPropertiesResponse(source, destination, linkMapper.map(goal), new EffectiveBfdProperties(linkMapper.map(goal), null), new EffectiveBfdProperties(linkMapper.map(BfdProperties.DISABLED), null), leftToRight, rightToLeft)));
    // make read request and schedule one more read
    monitorTaskCaptor.getValue().run();
    verify(taskScheduler).schedule(monitorTaskCaptor.capture(), any(Date.class));
    Assert.assertFalse(future.isDone());
    clock.adjust(Duration.ofSeconds(bfdPropertiesApplyPeriod));
    messageExchanger.mockChunkedResponse(makeBfdMonitorCorrelationId(correlationId, 1), Collections.singletonList(new BfdPropertiesResponse(source, destination, linkMapper.map(goal), new EffectiveBfdProperties(linkMapper.map(goal), null), new EffectiveBfdProperties(linkMapper.map(BfdProperties.DISABLED), null), leftToRight, rightToLeft)));
    // make read request and fail due to timeout
    monitorTaskCaptor.getValue().run();
    Assert.assertTrue(future.isDone());
    try {
        future.get();
        Assert.fail("ExecutionException exception expected");
    } catch (ExecutionException e) {
        Throwable cause = e.getCause();
        Assert.assertTrue(cause instanceof InconclusiveException);
    }
}
Also used : NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) InconclusiveException(org.openkilda.northbound.error.InconclusiveException) SwitchId(org.openkilda.model.SwitchId) PathNode(org.openkilda.messaging.info.event.PathNode) BfdPropertiesPayload(org.openkilda.northbound.dto.v2.links.BfdPropertiesPayload) Date(java.util.Date) BfdPropertiesResponse(org.openkilda.messaging.nbtopology.response.BfdPropertiesResponse) BfdProperties(org.openkilda.northbound.dto.v2.links.BfdProperties) EffectiveBfdProperties(org.openkilda.model.EffectiveBfdProperties) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) EffectiveBfdProperties(org.openkilda.model.EffectiveBfdProperties) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

IslInfoData (org.openkilda.messaging.info.event.IslInfoData)3 BfdPropertiesResponse (org.openkilda.messaging.nbtopology.response.BfdPropertiesResponse)3 Date (java.util.Date)2 Test (org.junit.Test)2 PathNode (org.openkilda.messaging.info.event.PathNode)2 NetworkEndpoint (org.openkilda.messaging.model.NetworkEndpoint)2 EffectiveBfdProperties (org.openkilda.model.EffectiveBfdProperties)2 SwitchId (org.openkilda.model.SwitchId)2 BfdProperties (org.openkilda.northbound.dto.v2.links.BfdProperties)2 BfdPropertiesPayload (org.openkilda.northbound.dto.v2.links.BfdPropertiesPayload)2 ExecutionException (java.util.concurrent.ExecutionException)1 MessageException (org.openkilda.messaging.error.MessageException)1 InfoData (org.openkilda.messaging.info.InfoData)1 InconclusiveException (org.openkilda.northbound.error.InconclusiveException)1