Search in sources :

Example 16 with IslInfoData

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

the class IslServiceImplTest method discoverIsl.

@Test
public void discoverIsl() throws Exception {
    PathNode srcNode = new PathNode(srcSwitchId, 1, 0);
    PathNode dstNode = new PathNode(dstSwitchId, 1, 1);
    List<PathNode> list = new ArrayList<>();
    list.add(srcNode);
    list.add(dstNode);
    IslInfoData forwardIsl = new IslInfoData(100L, list, 10000000L);
    islService.discoverLink(forwardIsl);
    Isl isl = islService.getLink(forwardIsl);
    assertNotNull(isl);
    assertEquals(100L, isl.getLatency());
}
Also used : Isl(org.openkilda.topology.domain.Isl) ArrayList(java.util.ArrayList) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) PathNode(org.openkilda.messaging.info.event.PathNode) Test(org.junit.Test)

Example 17 with IslInfoData

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

the class IslServiceImplTest method dropIsl.

@Test
public void dropIsl() throws Exception {
    PathNode srcNode = new PathNode(srcSwitchId, 1, 0);
    PathNode dstNode = new PathNode(dstSwitchId, 1, 1);
    List<PathNode> list = new ArrayList<>();
    list.add(srcNode);
    list.add(dstNode);
    IslInfoData forwardIsl = new IslInfoData(100L, list, 10000000L);
    islService.discoverLink(forwardIsl);
    Isl isl = islService.getLink(forwardIsl);
    assertNotNull(isl);
    assertEquals(100L, isl.getLatency());
    islService.dropLink(forwardIsl);
    isl = islService.getLink(forwardIsl);
    assertNull(isl);
}
Also used : Isl(org.openkilda.topology.domain.Isl) ArrayList(java.util.ArrayList) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) PathNode(org.openkilda.messaging.info.event.PathNode) Test(org.junit.Test)

Example 18 with IslInfoData

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

the class OFEMessageUtils method createIslFail.

public static String createIslFail(String switchId, String portId) throws IOException {
    PathNode node = new PathNode(switchId, Integer.parseInt(portId), 0, 0L);
    InfoData data = new IslInfoData(0L, Collections.singletonList(node), 0L, IslChangeType.FAILED, 0L);
    InfoMessage message = new InfoMessage(data, System.currentTimeMillis(), UUID.randomUUID().toString());
    return MAPPER.writeValueAsString(message);
}
Also used : IslInfoData(org.openkilda.messaging.info.event.IslInfoData) InfoData(org.openkilda.messaging.info.InfoData) InfoMessage(org.openkilda.messaging.info.InfoMessage) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) PathNode(org.openkilda.messaging.info.event.PathNode)

Example 19 with IslInfoData

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

the class OFELinkBolt method doWork.

@Override
protected void doWork(Tuple tuple) {
    if (CtrlAction.boltHandlerEntrance(this, tuple))
        return;
    // 
    // (crimi) - commenting out the filter code until we re-evaluate the design. Also, this code
    // should probably be embedded in "handleIslEvent"
    // /*
    // * Check whether ISL Filter needs to be engaged.
    // */
    // String source = tuple.getSourceComponent();
    // if (source.equals(OFEventWFMTopology.SPOUT_ID_INPUT)) {
    // PopulateIslFilterAction action = new PopulateIslFilterAction(this, tuple, islFilter);
    // action.run();
    // return;
    // }
    String json = tuple.getString(0);
    try {
        BaseMessage bm = MAPPER.readValue(json, BaseMessage.class);
        watchDog.reset();
        if (bm instanceof InfoMessage) {
            InfoData data = ((InfoMessage) bm).getData();
            if (data instanceof NetworkInfoData) {
                handleNetworkDump(tuple, (NetworkInfoData) data);
                isReceivedCacheInfo = true;
            } else if (!isReceivedCacheInfo) {
                logger.debug("Bolt is not initialized mark tuple as fail");
            } else if (data instanceof SwitchInfoData) {
                handleSwitchEvent(tuple, (SwitchInfoData) data);
                passToTopologyEngine(tuple);
            } else if (data instanceof PortInfoData) {
                handlePortEvent(tuple, (PortInfoData) data);
                passToTopologyEngine(tuple);
            } else if (data instanceof IslInfoData) {
                handleIslEvent(tuple, (IslInfoData) data);
            } else {
                logger.warn("Unknown InfoData type={}", data);
            }
        } else if (bm instanceof HeartBeat) {
            logger.debug("Got speaker's heart beat");
        }
    } catch (IOException e) {
        // All messages should be derived from BaseMessage .. so an exception here
        // means that we found something that isn't. If this criteria changes, then
        // change the logger level.
        logger.error("Unknown Message type={}", json);
    } finally {
        // We mark as fail all tuples while bolt is not initialized
        if (isReceivedCacheInfo) {
            collector.ack(tuple);
        } else {
            collector.fail(tuple);
        }
    }
}
Also used : HeartBeat(org.openkilda.messaging.HeartBeat) NetworkInfoData(org.openkilda.messaging.info.discovery.NetworkInfoData) BaseMessage(org.openkilda.messaging.BaseMessage) InfoMessage(org.openkilda.messaging.info.InfoMessage) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) NetworkInfoData(org.openkilda.messaging.info.discovery.NetworkInfoData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) InfoData(org.openkilda.messaging.info.InfoData) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) IOException(java.io.IOException) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData)

Example 20 with IslInfoData

use of org.openkilda.messaging.info.event.IslInfoData 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)

Aggregations

IslInfoData (org.openkilda.messaging.info.event.IslInfoData)29 PathNode (org.openkilda.messaging.info.event.PathNode)16 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)9 InfoMessage (org.openkilda.messaging.info.InfoMessage)8 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 When (cucumber.api.java.en.When)5 IOException (java.io.IOException)5 CommandMessage (org.openkilda.messaging.command.CommandMessage)5 InfoData (org.openkilda.messaging.info.InfoData)5 Then (cucumber.api.java.en.Then)4 List (java.util.List)4 Message (org.openkilda.messaging.Message)4 Comparator (java.util.Comparator)3 Collectors (java.util.stream.Collectors)3 CacheException (org.openkilda.messaging.error.CacheException)3 Isl (org.openkilda.topology.domain.Isl)3 PendingException (cucumber.api.PendingException)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2