Search in sources :

Example 16 with PathNode

use of org.openkilda.messaging.info.event.PathNode in project open-kilda by telstra.

the class OFELinkBolt method handleIslEvent.

private void handleIslEvent(Tuple tuple, IslInfoData discoveredIsl) {
    PathNode node = discoveredIsl.getPath().get(0);
    String switchID = node.getSwitchId();
    String portID = "" + node.getPortNo();
    IslChangeType state = discoveredIsl.getState();
    boolean stateChanged = false;
    /*
         * TODO: would be good to merge more of this behavior / business logic within DiscoveryManager
         *  The reason is so that we consolidate behavior related to Network Topology Discovery into
         *  one place.
         */
    if (IslChangeType.DISCOVERED.equals(state)) {
        stateChanged = discovery.handleDiscovered(switchID, portID);
        // sure we can test the other side as well.
        if (stateChanged && discoveredIsl.getPath().size() > 1) {
            String dstSwitch = discoveredIsl.getPath().get(0).getSwitchId();
            String dstPort = "" + discoveredIsl.getPath().get(0).getPortNo();
            if (!discovery.checkForIsl(dstSwitch, dstPort)) {
                // Only call PortUp if we aren't checking for ISL. Otherwise, we could end up in an
                // infinite cycle of always sending a Port UP when one side is discovered.
                discovery.handlePortUp(dstSwitch, dstPort);
            }
        }
    } else if (IslChangeType.FAILED.equals(state)) {
        stateChanged = discovery.handleFailed(switchID, portID);
    } else {
        // TODO: Should this be a warning? Evaluate whether any other state needs to be handled
        logger.warn("ISL Event: ignoring state: {}", state);
    }
    if (stateChanged) {
        // If the state changed, notify the TE.
        logger.info("DISCO: ISL Event: switch={} port={} state={}", switchID, portID, state);
        passToTopologyEngine(tuple);
    }
}
Also used : IslChangeType(org.openkilda.messaging.info.event.IslChangeType) PathNode(org.openkilda.messaging.info.event.PathNode)

Example 17 with PathNode

use of org.openkilda.messaging.info.event.PathNode in project open-kilda by telstra.

the class FlowTopologyTest method pathFlowCommand.

private PathInfoData pathFlowCommand(final String flowId) throws IOException {
    System.out.println("TOPOLOGY: Path flow");
    PathInfoData payload = new PathInfoData(0L, Collections.singletonList(new PathNode("test-switch", 1, 0, null)));
    FlowPathResponse infoData = new FlowPathResponse(payload);
    InfoMessage infoMessage = new InfoMessage(infoData, 0, "path-flow", Destination.WFM);
    sendTopologyEngineMessage(infoMessage);
    return payload;
}
Also used : PathInfoData(org.openkilda.messaging.info.event.PathInfoData) FlowPathResponse(org.openkilda.messaging.info.flow.FlowPathResponse) InfoMessage(org.openkilda.messaging.info.InfoMessage) PathNode(org.openkilda.messaging.info.event.PathNode)

Example 18 with PathNode

use of org.openkilda.messaging.info.event.PathNode in project open-kilda by telstra.

the class PathComputerMock method path.

private PathInfoData path(SwitchInfoData srcSwitch, SwitchInfoData dstSwitch, int bandwidth) {
    System.out.println("Get Path By Switch Instances " + bandwidth + ": " + srcSwitch + " - " + dstSwitch);
    LinkedList<IslInfoData> islInfoDataLinkedList = new LinkedList<>();
    List<PathNode> nodes = new ArrayList<>();
    PathInfoData path = new PathInfoData(0L, nodes);
    if (srcSwitch.equals(dstSwitch)) {
        return path;
    }
    Set<SwitchInfoData> nodesToProcess = new HashSet<>(network.nodes());
    Set<SwitchInfoData> nodesWereProcess = new HashSet<>();
    Map<SwitchInfoData, ImmutablePair<SwitchInfoData, IslInfoData>> predecessors = new HashMap<>();
    Map<SwitchInfoData, Long> distances = network.nodes().stream().collect(Collectors.toMap(k -> k, v -> Long.MAX_VALUE));
    distances.put(srcSwitch, 0L);
    while (!nodesToProcess.isEmpty()) {
        SwitchInfoData source = nodesToProcess.stream().min(Comparator.comparingLong(distances::get)).orElseThrow(() -> new CacheException(ErrorType.NOT_FOUND, "Can not find path", "Error: No nodes to process left"));
        nodesToProcess.remove(source);
        nodesWereProcess.add(source);
        for (SwitchInfoData target : network.successors(source)) {
            if (!nodesWereProcess.contains(target)) {
                IslInfoData edge = network.edgesConnecting(source, target).stream().filter(isl -> isl.getAvailableBandwidth() >= bandwidth).findFirst().orElseThrow(() -> new CacheException(ErrorType.NOT_FOUND, "Can not find path", "Error: No enough bandwidth"));
                Long distance = distances.get(source) + getWeight(edge);
                if (distances.get(target) >= distance) {
                    distances.put(target, distance);
                    nodesToProcess.add(target);
                    predecessors.put(target, new ImmutablePair<>(source, edge));
                }
            }
        }
    }
    ImmutablePair<SwitchInfoData, IslInfoData> nextHop = predecessors.get(dstSwitch);
    if (nextHop == null) {
        return null;
    }
    islInfoDataLinkedList.add(nextHop.getRight());
    while (predecessors.get(nextHop.getLeft()) != null) {
        nextHop = predecessors.get(nextHop.getLeft());
        islInfoDataLinkedList.add(nextHop.getRight());
    }
    Collections.reverse(islInfoDataLinkedList);
    int i = 0;
    for (IslInfoData isl : islInfoDataLinkedList) {
        collect(isl, path, i);
        i += 2;
    }
    updatePathBandwidth(path, bandwidth, islInfoDataLinkedList);
    return path;
}
Also used : Flow(org.openkilda.messaging.model.Flow) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) ImmutablePair(org.openkilda.messaging.model.ImmutablePair) ErrorType(org.openkilda.messaging.error.ErrorType) Set(java.util.Set) CacheException(org.openkilda.messaging.error.CacheException) HashMap(java.util.HashMap) PathNode(org.openkilda.messaging.info.event.PathNode) Collectors(java.util.stream.Collectors) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Map(java.util.Map) MutableNetwork(com.google.common.graph.MutableNetwork) Comparator(java.util.Comparator) LinkedList(java.util.LinkedList) Collections(java.util.Collections) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) HashMap(java.util.HashMap) CacheException(org.openkilda.messaging.error.CacheException) ArrayList(java.util.ArrayList) PathNode(org.openkilda.messaging.info.event.PathNode) LinkedList(java.util.LinkedList) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) ImmutablePair(org.openkilda.messaging.model.ImmutablePair) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) HashSet(java.util.HashSet)

Example 19 with PathNode

use of org.openkilda.messaging.info.event.PathNode in project open-kilda by telstra.

the class PathComputerMock method collect.

private void collect(IslInfoData isl, PathInfoData path, int seqId) {
    PathNode source = new PathNode(isl.getPath().get(0));
    source.setSeqId(seqId);
    source.setSegLatency(isl.getLatency());
    path.getPath().add(source);
    PathNode destination = new PathNode(isl.getPath().get(1));
    destination.setSeqId(seqId + 1);
    path.getPath().add(destination);
    path.setLatency(path.getLatency() + isl.getLatency());
}
Also used : PathNode(org.openkilda.messaging.info.event.PathNode)

Example 20 with PathNode

use of org.openkilda.messaging.info.event.PathNode in project open-kilda by telstra.

the class IslServiceImpl method getLink.

/**
 * {@inheritDoc}
 */
@Override
public Isl getLink(final IslInfoData data) {
    logger.debug("Isl get: isl={}", data);
    PathNode sourceNode = data.getPath().get(0);
    PathNode destinationNode = data.getPath().get(1);
    Isl isl = islRepository.findIsl(sourceNode.getSwitchId(), sourceNode.getPortNo(), destinationNode.getSwitchId(), destinationNode.getPortNo());
    logger.debug("Isl relationship found: {}", isl);
    return isl;
}
Also used : Isl(org.openkilda.topology.domain.Isl) PathNode(org.openkilda.messaging.info.event.PathNode)

Aggregations

PathNode (org.openkilda.messaging.info.event.PathNode)26 IslInfoData (org.openkilda.messaging.info.event.IslInfoData)14 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 Isl (org.openkilda.topology.domain.Isl)7 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)6 CommandMessage (org.openkilda.messaging.command.CommandMessage)5 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)4 HashSet (java.util.HashSet)3 InfoMessage (org.openkilda.messaging.info.InfoMessage)3 Then (cucumber.api.java.en.Then)2 Set (java.util.Set)2 Message (org.openkilda.messaging.Message)2 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)2 InfoData (org.openkilda.messaging.info.InfoData)2 ImmutablePair (org.openkilda.messaging.model.ImmutablePair)2 Switch (org.openkilda.topology.domain.Switch)2 AbstractStormTest (org.openkilda.wfm.AbstractStormTest)2 JWTVerificationException (com.auth0.jwt.exceptions.JWTVerificationException)1 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)1