Search in sources :

Example 16 with Isl

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));
}
Also used : Isl(org.openkilda.model.Isl)

Example 17 with Isl

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);
}
Also used : Isl(org.openkilda.model.Isl) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 18 with Isl

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;
    });
}
Also used : Isl(org.openkilda.model.Isl) LinkProps(org.openkilda.model.LinkProps)

Example 19 with Isl

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());
}
Also used : IslEndpoint(org.openkilda.model.IslEndpoint) Isl(org.openkilda.model.Isl) CommandContext(org.openkilda.wfm.CommandContext) Values(org.apache.storm.tuple.Values) SwitchId(org.openkilda.model.SwitchId) MessageException(org.openkilda.messaging.error.MessageException) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) IslNotFoundException(org.openkilda.wfm.error.IslNotFoundException) FlowPath(org.openkilda.model.FlowPath) HashSet(java.util.HashSet) IslMapper(org.openkilda.wfm.share.mappers.IslMapper)

Example 20 with Isl

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;
    });
}
Also used : Isl(org.openkilda.model.Isl) LinkPropsException(org.openkilda.wfm.error.LinkPropsException) LinkProps(org.openkilda.model.LinkProps)

Aggregations

Isl (org.openkilda.model.Isl)83 Test (org.junit.Test)49 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)25 Endpoint (org.openkilda.wfm.share.model.Endpoint)18 Switch (org.openkilda.model.Switch)17 IslReference (org.openkilda.wfm.share.model.IslReference)11 SwitchId (org.openkilda.model.SwitchId)10 IslInfoData (org.openkilda.messaging.info.event.IslInfoData)9 IslDataHolder (org.openkilda.wfm.topology.network.model.IslDataHolder)8 ArrayList (java.util.ArrayList)6 PathId (org.openkilda.model.PathId)6 Flow (org.openkilda.model.Flow)5 IslRepository (org.openkilda.persistence.repositories.IslRepository)5 Collection (java.util.Collection)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 FlowPath (org.openkilda.model.FlowPath)4 PersistenceException (org.openkilda.persistence.exceptions.PersistenceException)4 IslFrame (org.openkilda.persistence.ferma.frames.IslFrame)4