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