use of org.openkilda.model.Isl in project open-kilda by telstra.
the class LinkOperationsService method readBfdPropertiesTransaction.
private BfdPropertiesResponse readBfdPropertiesTransaction(Endpoint source, Endpoint destination) throws IslNotFoundException {
Isl leftToRight = findIsl(source, destination);
Isl rightToLeft = findIsl(destination, source);
IslPair link = new IslPair(source, destination, leftToRight, rightToLeft);
return makeBfdPropertiesResponse(link.detach(islRepository));
}
use of org.openkilda.model.Isl in project open-kilda by telstra.
the class LinkOperationsServiceTest method shouldFailIfThereIsUniIslOnlyForBfdPropertiesUpdateRequest.
@Test(expected = IslNotFoundException.class)
public void shouldFailIfThereIsUniIslOnlyForBfdPropertiesUpdateRequest() throws IslNotFoundException {
Isl isl = Isl.builder().srcSwitch(createSwitchIfNotExist(TEST_SWITCH_A_ID)).srcPort(TEST_SWITCH_A_PORT).destSwitch(createSwitchIfNotExist(TEST_SWITCH_B_ID)).destPort(TEST_SWITCH_B_PORT).cost(0).status(IslStatus.ACTIVE).build();
islRepository.add(isl);
linkOperationsService.writeBfdProperties(Endpoint.of(TEST_SWITCH_A_ID, TEST_SWITCH_A_PORT), Endpoint.of(TEST_SWITCH_B_ID, TEST_SWITCH_B_PORT), defaultBfdProperties);
}
use of org.openkilda.model.Isl in project open-kilda by telstra.
the class LinkOperationsBolt method deleteLinkProps.
private LinkProps deleteLinkProps(LinkProps fwdLinkProps, LinkProps rvsLinkProps) {
List<LinkProps> linkProperties = Arrays.asList(rvsLinkProps, fwdLinkProps);
return transactionManager.doInTransaction(() -> {
LinkProps linkProps = null;
for (LinkProps linkPropsToDrop : linkProperties) {
Collection<LinkProps> existingLinkProps = linkPropsRepository.findByEndpoints(linkPropsToDrop.getSrcSwitchId(), linkPropsToDrop.getSrcPort(), linkPropsToDrop.getDstSwitchId(), linkPropsToDrop.getDstPort());
if (!existingLinkProps.isEmpty()) {
linkProps = existingLinkProps.iterator().next();
linkPropsRepository.remove(linkProps);
}
Optional<Isl> existingIsl = islRepository.findByEndpoints(linkPropsToDrop.getSrcSwitchId(), linkPropsToDrop.getSrcPort(), linkPropsToDrop.getDstSwitchId(), linkPropsToDrop.getDstPort());
long propsMaxBandwidth = (linkProps != null ? linkProps.getMaxBandwidth() : null) != null ? linkProps.getMaxBandwidth() : 0L;
existingIsl.ifPresent(link -> {
link.setCost(0);
link.setMaxBandwidth(link.getDefaultMaxBandwidth());
if (propsMaxBandwidth > 0) {
long availableBandwidth = link.getDefaultMaxBandwidth() - (propsMaxBandwidth - link.getAvailableBandwidth());
link.setAvailableBandwidth(availableBandwidth);
}
});
}
return linkProps;
});
}
use of org.openkilda.model.Isl in project open-kilda by telstra.
the class LinkOperationsBolt method updateLinkUnderMaintenanceFlag.
private List<IslInfoData> updateLinkUnderMaintenanceFlag(UpdateLinkUnderMaintenanceRequest request) {
SwitchId srcSwitch = request.getSource().getDatapath();
Integer srcPort = request.getSource().getPortNumber();
SwitchId dstSwitch = request.getDestination().getDatapath();
Integer dstPort = request.getDestination().getPortNumber();
boolean underMaintenance = request.isUnderMaintenance();
boolean evacuate = request.isEvacuate();
List<Isl> isl;
try {
isl = linkOperationsService.updateLinkUnderMaintenanceFlag(srcSwitch, srcPort, dstSwitch, dstPort, underMaintenance);
if (underMaintenance && evacuate) {
Set<IslEndpoint> affectedIslEndpoints = new HashSet<>();
affectedIslEndpoints.add(new IslEndpoint(srcSwitch, srcPort));
affectedIslEndpoints.add(new IslEndpoint(dstSwitch, dstPort));
String reason = format("evacuated due to link maintenance %s_%d - %s_%d", srcSwitch, srcPort, dstSwitch, dstPort);
Collection<FlowPath> targetPaths = flowOperationsService.getFlowPathsForLink(srcSwitch, srcPort, dstSwitch, dstPort);
for (FlowRerouteRequest reroute : flowOperationsService.makeRerouteRequests(targetPaths, affectedIslEndpoints, reason)) {
CommandContext forkedContext = getCommandContext().fork(reroute.getFlowId());
getOutput().emit(StreamType.REROUTE.toString(), getCurrentTuple(), new Values(reroute, forkedContext.getCorrelationId()));
}
}
} catch (IslNotFoundException e) {
throw new MessageException(ErrorType.NOT_FOUND, e.getMessage(), "ISL was not found.");
}
return isl.stream().map(IslMapper.INSTANCE::map).collect(Collectors.toList());
}
use of org.openkilda.model.Isl in project open-kilda by telstra.
the class LinkOperationsBolt method createOrUpdateProps.
private LinkProps createOrUpdateProps(LinkProps linkPropsToSet) throws MessageException {
return transactionManager.doInTransaction(() -> {
Collection<LinkProps> existingLinkProps = linkPropsRepository.findByEndpoints(linkPropsToSet.getSrcSwitchId(), linkPropsToSet.getSrcPort(), linkPropsToSet.getDstSwitchId(), linkPropsToSet.getDstPort());
LinkProps linkProps;
if (!existingLinkProps.isEmpty()) {
linkProps = existingLinkProps.iterator().next();
if (linkPropsToSet.getCost() != null) {
linkProps.setCost(linkPropsToSet.getCost());
}
if (linkPropsToSet.getMaxBandwidth() != null) {
linkProps.setMaxBandwidth(linkPropsToSet.getMaxBandwidth());
}
} else {
linkProps = new LinkProps(linkPropsToSet);
linkPropsRepository.add(linkProps);
}
Optional<Isl> existingIsl = islRepository.findByEndpoints(linkPropsToSet.getSrcSwitchId(), linkPropsToSet.getSrcPort(), linkPropsToSet.getDstSwitchId(), linkPropsToSet.getDstPort());
existingIsl.ifPresent(link -> {
if (linkPropsToSet.getCost() != null) {
link.setCost(linkPropsToSet.getCost());
}
if (linkPropsToSet.getMaxBandwidth() != null) {
long currentMaxBandwidth = link.getMaxBandwidth();
long currentAvailableBandwidth = link.getAvailableBandwidth();
long availableBandwidth = linkPropsToSet.getMaxBandwidth() - (currentMaxBandwidth - currentAvailableBandwidth);
link.setMaxBandwidth(linkPropsToSet.getMaxBandwidth());
if (availableBandwidth < 0) {
throw new LinkPropsException("Not enough available bandwidth for operation");
}
link.setAvailableBandwidth(availableBandwidth);
}
});
return linkProps;
});
}
Aggregations