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()));
}
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);
}
}
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);
}
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()));
}
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));
}
Aggregations