Search in sources :

Example 41 with IslInfoData

use of org.openkilda.messaging.info.event.IslInfoData in project open-kilda by telstra.

the class IslMapper method map.

/**
 * Convert {@link Isl} to {@link IslInfoData}.
 */
public IslInfoData map(Isl isl) {
    if (isl == null) {
        return null;
    }
    PathNode src = new PathNode();
    src.setSwitchId(isl.getSrcSwitchId());
    src.setPortNo(isl.getSrcPort());
    src.setSegLatency(isl.getLatency());
    src.setSeqId(0);
    PathNode dst = new PathNode();
    dst.setSwitchId(isl.getDestSwitchId());
    dst.setPortNo(isl.getDestPort());
    dst.setSegLatency(isl.getLatency());
    dst.setSeqId(1);
    Long timeCreateMillis = Optional.ofNullable(isl.getTimeCreate()).map(Instant::toEpochMilli).orElse(null);
    Long timeModifyMillis = Optional.ofNullable(isl.getTimeModify()).map(Instant::toEpochMilli).orElse(null);
    BfdProperties bfdProperties = readBfdProperties(isl);
    return new IslInfoData(isl.getLatency(), src, dst, isl.getSpeed(), isl.getAvailableBandwidth(), isl.getMaxBandwidth(), isl.getDefaultMaxBandwidth(), map(isl.getStatus()), map(isl.getActualStatus()), map(isl.getRoundTripStatus()), isl.getCost(), timeCreateMillis, timeModifyMillis, isl.isUnderMaintenance(), bfdProperties.isEnabled(), map(isl.getBfdSessionStatus()), null);
}
Also used : BfdProperties(org.openkilda.model.BfdProperties) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) PathNode(org.openkilda.messaging.info.event.PathNode)

Example 42 with IslInfoData

use of org.openkilda.messaging.info.event.IslInfoData in project open-kilda by telstra.

the class LinkServiceTest method testLinkUnderMaintenance.

@Test
public void testLinkUnderMaintenance() {
    String correlationId = "links-list";
    SwitchId switchId = new SwitchId(1L);
    boolean underMaintenance = true;
    boolean evacuate = false;
    IslInfoData islInfoData = new IslInfoData(new PathNode(switchId, 1, 0), new PathNode(switchId, 2, 1), IslChangeType.DISCOVERED, true);
    messageExchanger.mockChunkedResponse(correlationId, Collections.singletonList(islInfoData));
    RequestCorrelationId.create(correlationId);
    LinkUnderMaintenanceDto linkUnderMaintenanceDto = new LinkUnderMaintenanceDto(islInfoData.getSource().getSwitchId().toString(), islInfoData.getSource().getPortNo(), islInfoData.getDestination().getSwitchId().toString(), islInfoData.getDestination().getPortNo(), underMaintenance, evacuate);
    List<LinkDto> result = linkService.updateLinkUnderMaintenance(linkUnderMaintenanceDto).join();
    assertFalse("List of link shouldn't be empty", result.isEmpty());
    LinkDto link = result.get(0);
    assertThat(link.isUnderMaintenance(), is(true));
    assertThat(link.getState(), is(LinkStatus.DISCOVERED));
    assertFalse(link.getPath().isEmpty());
    PathDto path = link.getPath().get(0);
    assertThat(path.getSwitchId(), is(switchId.toString()));
    assertThat(path.getPortNo(), is(1));
}
Also used : PathDto(org.openkilda.northbound.dto.v1.links.PathDto) LinkDto(org.openkilda.northbound.dto.v1.links.LinkDto) SwitchId(org.openkilda.model.SwitchId) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) PathNode(org.openkilda.messaging.info.event.PathNode) LinkUnderMaintenanceDto(org.openkilda.northbound.dto.v1.links.LinkUnderMaintenanceDto) Test(org.junit.Test)

Example 43 with IslInfoData

use of org.openkilda.messaging.info.event.IslInfoData 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)

Example 44 with IslInfoData

use of org.openkilda.messaging.info.event.IslInfoData in project open-kilda by telstra.

the class FlowSteps method getAvailableBandwidthAndSpeed.

@And("^get available bandwidth and maximum speed for flow (.*) and alias them as '(.*)' " + "and '(.*)' respectively$")
public void getAvailableBandwidthAndSpeed(String flowAlias, String bwAlias, String speedAlias) {
    FlowPayload flow = topologyUnderTest.getAliasedObject(flowAlias);
    List<PathNodePayload> flowPath = northboundService.getFlowPath(flow.getId()).getForwardPath();
    List<IslInfoData> allLinks = northboundService.getAllLinks();
    long minBw = Long.MAX_VALUE;
    long minSpeed = Long.MAX_VALUE;
    /*
        Take flow path and all links. Now for every pair in flow path find a link.
        Take minimum available bandwidth and minimum available speed from those links
        (flow's speed and left bandwidth depends on the weakest isl)
        */
    for (int i = 1; i < flowPath.size(); i++) {
        PathNodePayload from = flowPath.get(i - 1);
        PathNodePayload to = flowPath.get(i);
        IslInfoData isl = allLinks.stream().filter(link -> link.getSource().getSwitchId().equals(from.getSwitchId()) && link.getDestination().getSwitchId().equals(to.getSwitchId())).findFirst().orElseThrow(() -> new IllegalStateException(format("Isl from %s to %s not found.", from.getSwitchId(), to.getSwitchId())));
        minBw = Math.min(isl.getAvailableBandwidth(), minBw);
        minSpeed = Math.min(isl.getSpeed(), minSpeed);
    }
    topologyUnderTest.addAlias(bwAlias, minBw);
    topologyUnderTest.addAlias(speedAlias, minSpeed);
}
Also used : FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) PathNodePayload(org.openkilda.messaging.payload.flow.PathNodePayload) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) And(cucumber.api.java.en.And)

Example 45 with IslInfoData

use of org.openkilda.messaging.info.event.IslInfoData in project open-kilda by telstra.

the class LinksUtils method dumpLinks.

/**
 * Returns links through Topology-Engine-Rest service.
 *
 * @return The JSON document of all flows
 */
public static List<IslInfoData> dumpLinks() {
    System.out.println("\n==> Topology-Engine Dump Links");
    long current = System.currentTimeMillis();
    Client client = ClientBuilder.newClient(new ClientConfig());
    Response response = client.target(topologyEndpoint).path("/api/v1/topology/links").request().header(HttpHeaders.AUTHORIZATION, authHeaderValue).get();
    System.out.println(String.format("===> Response = %s", response.toString()));
    System.out.println(String.format("===> Topology-Engine Dump Links Time: %,.3f", getTimeDuration(current)));
    try {
        List<IslInfoData> links = new ObjectMapper().readValue(response.readEntity(String.class), new TypeReference<List<IslInfoData>>() {
        });
        // LOGGER.debug(String.format("====> Data = %s", links));
        return links;
    } catch (IOException ex) {
        throw new TopologyProcessingException(format("Unable to parse the links '%s'.", response.toString()), ex);
    }
}
Also used : Response(javax.ws.rs.core.Response) TopologyProcessingException(org.openkilda.topo.exceptions.TopologyProcessingException) List(java.util.List) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) IOException(java.io.IOException) Client(javax.ws.rs.client.Client) ClientConfig(org.glassfish.jersey.client.ClientConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

IslInfoData (org.openkilda.messaging.info.event.IslInfoData)51 PathNode (org.openkilda.messaging.info.event.PathNode)29 Test (org.junit.Test)25 Endpoint (org.openkilda.wfm.share.model.Endpoint)12 SwitchId (org.openkilda.model.SwitchId)10 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)9 Isl (org.openkilda.model.Isl)9 InfoMessage (org.openkilda.messaging.info.InfoMessage)8 ArrayList (java.util.ArrayList)6 When (cucumber.api.java.en.When)5 IOException (java.io.IOException)5 InfoData (org.openkilda.messaging.info.InfoData)5 Switch (org.openkilda.model.Switch)5 Then (cucumber.api.java.en.Then)4 List (java.util.List)4 CommandMessage (org.openkilda.messaging.command.CommandMessage)4 Comparator (java.util.Comparator)3 Collectors (java.util.stream.Collectors)3 Message (org.openkilda.messaging.Message)3 CacheException (org.openkilda.messaging.error.CacheException)3