Search in sources :

Example 1 with LinkDto

use of org.openkilda.northbound.dto.v1.links.LinkDto in project open-kilda by telstra.

the class JsonSerializationTest method linksDtoTest.

@Test
public void linksDtoTest() throws IOException {
    LinkDto dto = new LinkDto(-1, 1, 0, 0, 0, LinkStatus.DISCOVERED, LinkStatus.DISCOVERED, LinkStatus.FAILED, 0, false, false, "bfd-session-status", singletonList(new PathDto(SWITCH_ID, 1, 0, 10L)));
    assertEquals(dto, pass(dto, LinkDto.class));
}
Also used : PathDto(org.openkilda.northbound.dto.v1.links.PathDto) LinkDto(org.openkilda.northbound.dto.v1.links.LinkDto) Test(org.junit.Test)

Example 2 with LinkDto

use of org.openkilda.northbound.dto.v1.links.LinkDto in project open-kilda by telstra.

the class LinkMapperTest method testMapResponse.

@Test
public void testMapResponse() {
    PathNode source = new PathNode(SWITCH_ID_1, PORT_NUMBER_1, 0);
    PathNode destination = new PathNode(SWITCH_ID_2, PORT_NUMBER_2, 0);
    IslInfoData islInfoData = new IslInfoData(LATENCY, source, destination, SPEED, AVAILABLE_BANDWIDTH, MAX_BANDWIDTH, DEFAULT_MAX_BANDWIDTH, IslChangeType.DISCOVERED, IslChangeType.FAILED, IslChangeType.MOVED, COST, TIME_CREATE_MILLIS, TIME_MODIFY_MILLIS, false, true, BFD_SESSION_STATUS, PACKET_ID);
    LinkDto response = linkMapper.mapResponse(islInfoData);
    assertEquals(2, response.getPath().size());
    assertPathNode(source, response.getPath().get(0));
    assertPathNode(destination, response.getPath().get(1));
    assertEquals(LATENCY, response.getLatency());
    assertEquals(SPEED, response.getSpeed());
    assertEquals(AVAILABLE_BANDWIDTH, response.getAvailableBandwidth());
    assertEquals(MAX_BANDWIDTH, response.getMaxBandwidth());
    assertEquals(DEFAULT_MAX_BANDWIDTH, response.getDefaultMaxBandwidth());
    assertEquals(LinkStatus.DISCOVERED, response.getState());
    assertEquals(LinkStatus.FAILED, response.getActualState());
    assertEquals(LinkStatus.MOVED, response.getRoundTripStatus());
    assertEquals(COST, response.getCost());
    assertFalse(response.isUnderMaintenance());
    assertTrue(response.isEnableBfd());
    assertEquals(BFD_SESSION_STATUS, response.getBfdSessionStatus());
}
Also used : LinkDto(org.openkilda.northbound.dto.v1.links.LinkDto) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) PathNode(org.openkilda.messaging.info.event.PathNode) Test(org.junit.Test)

Example 3 with LinkDto

use of org.openkilda.northbound.dto.v1.links.LinkDto in project open-kilda by telstra.

the class LinkServiceTest method shouldGetLinksList.

@Test
public void shouldGetLinksList() {
    String correlationId = "links-list";
    SwitchId switchId = new SwitchId(1L);
    IslInfoData islInfoData = new IslInfoData(new PathNode(switchId, 1, 0), new PathNode(switchId, 2, 1), IslChangeType.DISCOVERED, false);
    messageExchanger.mockChunkedResponse(correlationId, Collections.singletonList(islInfoData));
    RequestCorrelationId.create(correlationId);
    List<LinkDto> result = linkService.getLinks(islInfoData.getSource().getSwitchId(), islInfoData.getSource().getPortNo(), islInfoData.getDestination().getSwitchId(), islInfoData.getDestination().getPortNo()).join();
    assertFalse("List of link shouldn't be empty", result.isEmpty());
    LinkDto link = result.get(0);
    assertThat(link.getSpeed(), is(0L));
    assertThat(link.getMaxBandwidth(), is(0L));
    assertThat(link.getAvailableBandwidth(), is(0L));
    assertThat(link.getCost(), is(0));
    assertThat(link.isUnderMaintenance(), is(false));
    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));
    path = link.getPath().get(1);
    assertThat(path.getSwitchId(), is(switchId.toString()));
    assertThat(path.getPortNo(), is(2));
}
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) Test(org.junit.Test)

Example 4 with LinkDto

use of org.openkilda.northbound.dto.v1.links.LinkDto in project open-kilda by telstra.

the class NorthboundServiceImpl method getLinks.

@Override
public List<IslInfoData> getLinks(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort) {
    UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUriString("/api/v1/links");
    if (srcSwitch != null) {
        uriBuilder.queryParam("src_switch", srcSwitch);
    }
    if (srcPort != null) {
        uriBuilder.queryParam("src_port", srcPort);
    }
    if (dstSwitch != null) {
        uriBuilder.queryParam("dst_switch", dstSwitch);
    }
    if (dstPort != null) {
        uriBuilder.queryParam("dst_port", dstPort);
    }
    LinkDto[] links = restTemplate.exchange(uriBuilder.build().toString(), HttpMethod.GET, new HttpEntity(buildHeadersWithCorrelationId()), LinkDto[].class).getBody();
    return Stream.of(links).map(this::convertToIslInfoData).collect(Collectors.toList());
}
Also used : LinkDto(org.openkilda.northbound.dto.v1.links.LinkDto) HttpEntity(org.springframework.http.HttpEntity) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder)

Example 5 with LinkDto

use of org.openkilda.northbound.dto.v1.links.LinkDto 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)

Aggregations

LinkDto (org.openkilda.northbound.dto.v1.links.LinkDto)6 Test (org.junit.Test)4 IslInfoData (org.openkilda.messaging.info.event.IslInfoData)3 PathNode (org.openkilda.messaging.info.event.PathNode)3 PathDto (org.openkilda.northbound.dto.v1.links.PathDto)3 SwitchId (org.openkilda.model.SwitchId)2 LinkUnderMaintenanceDto (org.openkilda.northbound.dto.v1.links.LinkUnderMaintenanceDto)1 HttpEntity (org.springframework.http.HttpEntity)1 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)1