Search in sources :

Example 1 with BfdPropertiesPayload

use of org.openkilda.northbound.dto.v2.links.BfdPropertiesPayload in project open-kilda by telstra.

the class LinkMapper method mapResponse.

/**
 * Convert {@link BfdPropertiesResponse} into {@link BfdPropertiesPayload}.
 */
@Mapping(target = "intervalMs", source = "properties.interval")
@Mapping(target = "multiplier", source = "properties.multiplier")
public BfdPropertiesPayload mapResponse(BfdPropertiesResponse response) {
    org.openkilda.northbound.dto.v2.links.BfdProperties properties = map(response.getGoal());
    BfdPropertiesByEndpoint effectiveSource = new BfdPropertiesByEndpoint(response.getSource(), map(response.getEffectiveSource()), map(response.getEffectiveSource().getStatus()));
    BfdPropertiesByEndpoint effectiveDestination = new BfdPropertiesByEndpoint(response.getDestination(), map(response.getEffectiveDestination()), map(response.getEffectiveDestination().getStatus()));
    return new BfdPropertiesPayload(properties, effectiveSource, effectiveDestination);
}
Also used : BfdPropertiesPayload(org.openkilda.northbound.dto.v2.links.BfdPropertiesPayload) BfdPropertiesByEndpoint(org.openkilda.northbound.dto.v2.links.BfdPropertiesByEndpoint) Mapping(org.mapstruct.Mapping)

Example 2 with BfdPropertiesPayload

use of org.openkilda.northbound.dto.v2.links.BfdPropertiesPayload 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 BfdPropertiesPayload

use of org.openkilda.northbound.dto.v2.links.BfdPropertiesPayload 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

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