Search in sources :

Example 26 with NetworkEndpoint

use of org.openkilda.messaging.model.NetworkEndpoint in project open-kilda by telstra.

the class LinkServiceTest method shouldGetPropsList.

@Test
public void shouldGetPropsList() {
    final String correlationId = "non-empty-link-props";
    org.openkilda.messaging.model.LinkPropsDto linkProps = new org.openkilda.messaging.model.LinkPropsDto(new NetworkEndpoint(new SwitchId("00:00:00:00:00:00:00:01"), 1), new NetworkEndpoint(new SwitchId("00:00:00:00:00:00:00:02"), 2), Collections.singletonMap("cost", "2"));
    LinkPropsData linkPropsData = new LinkPropsData(linkProps);
    messageExchanger.mockChunkedResponse(correlationId, Collections.singletonList(linkPropsData));
    RequestCorrelationId.create(correlationId);
    List<LinkPropsDto> result = linkService.getLinkProps(null, 0, null, 0).join();
    assertFalse("List of link props shouldn't be empty", result.isEmpty());
    LinkPropsDto dto = result.get(0);
    assertThat(dto.getSrcSwitch(), is(linkPropsData.getLinkProps().getSource().getDatapath().toString()));
    assertThat(dto.getSrcPort(), is(linkPropsData.getLinkProps().getSource().getPortNumber()));
    assertThat(dto.getDstSwitch(), is(linkPropsData.getLinkProps().getDest().getDatapath().toString()));
    assertThat(dto.getDstPort(), is(linkPropsData.getLinkProps().getDest().getPortNumber()));
}
Also used : NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) LinkPropsDto(org.openkilda.northbound.dto.v1.links.LinkPropsDto) LinkPropsData(org.openkilda.messaging.nbtopology.response.LinkPropsData) SwitchId(org.openkilda.model.SwitchId) Test(org.junit.Test)

Example 27 with NetworkEndpoint

use of org.openkilda.messaging.model.NetworkEndpoint 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 28 with NetworkEndpoint

use of org.openkilda.messaging.model.NetworkEndpoint in project open-kilda by telstra.

the class PingProducer method buildPing.

private Ping buildPing(PingContext pingContext, FlowDirection direction) {
    Flow flow = pingContext.getFlow();
    FlowEndpoint ingress;
    FlowEndpoint egress;
    int islPort;
    if (FlowDirection.FORWARD == direction) {
        ingress = new FlowSourceAdapter(flow).getEndpoint();
        egress = new FlowDestAdapter(flow).getEndpoint();
        islPort = getIslPort(flow, flow.getForwardPath());
    } else if (FlowDirection.REVERSE == direction) {
        ingress = new FlowDestAdapter(flow).getEndpoint();
        egress = new FlowSourceAdapter(flow).getEndpoint();
        islPort = getIslPort(flow, flow.getReversePath());
    } else {
        throw new IllegalArgumentException(String.format("Unexpected %s value: %s", FlowDirection.class.getCanonicalName(), direction));
    }
    return new Ping(new NetworkEndpoint(ingress.getSwitchId(), ingress.getPortNumber()), new NetworkEndpoint(egress.getSwitchId(), egress.getPortNumber()), pingContext.getTransitEncapsulation(), islPort);
}
Also used : FlowSourceAdapter(org.openkilda.adapter.FlowSourceAdapter) FlowEndpoint(org.openkilda.model.FlowEndpoint) NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) FlowDirection(org.openkilda.messaging.model.FlowDirection) FlowDestAdapter(org.openkilda.adapter.FlowDestAdapter) Ping(org.openkilda.messaging.model.Ping) FlowEndpoint(org.openkilda.model.FlowEndpoint) NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) Flow(org.openkilda.model.Flow)

Example 29 with NetworkEndpoint

use of org.openkilda.messaging.model.NetworkEndpoint in project open-kilda by telstra.

the class LinkServiceImpl method updateLinkBandwidth.

/**
 * {@inheritDoc}
 */
@Override
public CompletableFuture<LinkMaxBandwidthDto> updateLinkBandwidth(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort, LinkMaxBandwidthRequest input) {
    if (input.getMaxBandwidth() == null || input.getMaxBandwidth() < 0) {
        throw new MessageException(ErrorType.PARAMETERS_INVALID, "Invalid value of max_bandwidth", "Maximum bandwidth must not be null");
    }
    if (srcPort < 0) {
        throw new MessageException(ErrorType.PARAMETERS_INVALID, "Invalid value of source port", "Port number can't be negative");
    }
    if (dstPort < 0) {
        throw new MessageException(ErrorType.PARAMETERS_INVALID, "Invalid value of destination port", "Port number can't be negative");
    }
    org.openkilda.messaging.model.LinkPropsDto linkProps = org.openkilda.messaging.model.LinkPropsDto.builder().source(new NetworkEndpoint(srcSwitch, srcPort)).dest(new NetworkEndpoint(dstSwitch, dstPort)).props(ImmutableMap.of(LinkProps.MAX_BANDWIDTH_PROP_NAME, input.getMaxBandwidth().toString())).build();
    LinkPropsPut request = new LinkPropsPut(linkProps);
    String correlationId = RequestCorrelationId.getId();
    CommandMessage message = new CommandMessage(request, System.currentTimeMillis(), correlationId);
    return messagingChannel.sendAndGet(nbworkerTopic, message).thenApply(response -> linkPropsMapper.toLinkMaxBandwidth(((LinkPropsResponse) response).getLinkProps()));
}
Also used : LinkPropsResponse(org.openkilda.messaging.nbtopology.response.LinkPropsResponse) NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) MessageException(org.openkilda.messaging.error.MessageException) LinkPropsPut(org.openkilda.messaging.nbtopology.request.LinkPropsPut) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 30 with NetworkEndpoint

use of org.openkilda.messaging.model.NetworkEndpoint in project open-kilda by telstra.

the class LinkControllerV2 method bfdPropertiesWrite.

/**
 * Write/update/enable BFD properties for specific ISL.
 */
@ApiOperation(value = "Set/update BFD properties", response = BfdPropertiesPayload.class)
@PutMapping(value = "/{src-switch}_{src-port}/{dst-switch}_{dst-port}/bfd")
@ResponseStatus(HttpStatus.OK)
public CompletableFuture<BfdPropertiesPayload> bfdPropertiesWrite(@PathVariable("src-switch") SwitchId srcSwitchId, @PathVariable("src-port") int srcPortNumber, @PathVariable("dst-switch") SwitchId dstSwitchId, @PathVariable("dst-port") int dstPortNumber, @RequestBody BfdProperties payload) {
    verifyRequest(payload);
    NetworkEndpoint source = makeSourceEndpoint(srcSwitchId, srcPortNumber);
    NetworkEndpoint dest = makeDestinationEndpoint(dstSwitchId, dstPortNumber);
    return linkService.writeBfdProperties(source, dest, verifyRequest(payload));
}
Also used : NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Aggregations

NetworkEndpoint (org.openkilda.messaging.model.NetworkEndpoint)32 SwitchId (org.openkilda.model.SwitchId)16 Test (org.junit.Test)14 Ping (org.openkilda.messaging.model.Ping)7 CommandMessage (org.openkilda.messaging.command.CommandMessage)5 InfoMessage (org.openkilda.messaging.info.InfoMessage)5 LinkPropsDto (org.openkilda.messaging.model.LinkPropsDto)5 LinkPropsResponse (org.openkilda.messaging.nbtopology.response.LinkPropsResponse)5 FlowTransitEncapsulation (org.openkilda.model.FlowTransitEncapsulation)5 ApiOperation (io.swagger.annotations.ApiOperation)4 HashMap (java.util.HashMap)4 MessageException (org.openkilda.messaging.error.MessageException)4 LinkPropsPut (org.openkilda.messaging.nbtopology.request.LinkPropsPut)4 LinkPropsDto (org.openkilda.northbound.dto.v1.links.LinkPropsDto)4 Ethernet (net.floodlightcontroller.packet.Ethernet)3 IPacket (net.floodlightcontroller.packet.IPacket)3 InputService (org.openkilda.floodlight.service.of.InputService)3 DatapathId (org.projectfloodlight.openflow.types.DatapathId)3 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)3 Date (java.util.Date)2