Search in sources :

Example 31 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 32 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 33 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)

Example 34 with IslInfoData

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

the class AbstractSerializerTest method eventIslInfoTest.

@Test
public void eventIslInfoTest() throws IOException, ClassNotFoundException {
    PathNode payload = new PathNode(SWITCH_ID, INPUT_PORT, 0);
    IslInfoData data = new IslInfoData(0L, Collections.singletonList(payload), 1000000L, IslChangeType.DISCOVERED, 900000L);
    assertEquals(SWITCH_ID + "_" + String.valueOf(INPUT_PORT), data.getId());
    System.out.println(data);
    InfoMessage info = new InfoMessage(data, System.currentTimeMillis(), CORRELATION_ID, DESTINATION);
    serialize(info);
    Message message = (Message) deserialize();
    assertTrue(message instanceof InfoMessage);
    InfoMessage resultInfo = (InfoMessage) message;
    assertTrue(resultInfo.getData() instanceof IslInfoData);
    IslInfoData resultData = (IslInfoData) resultInfo.getData();
    System.out.println(resultData);
    assertEquals(data, resultData);
    assertEquals(data.hashCode(), resultData.hashCode());
    assertEquals(payload.hashCode(), resultData.getPath().get(0).hashCode());
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) InfoMessage(org.openkilda.messaging.info.InfoMessage) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) PathNode(org.openkilda.messaging.info.event.PathNode) Test(org.junit.Test)

Example 35 with IslInfoData

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

the class FlowCacheTest method buildNetworkTopology.

private void buildNetworkTopology(NetworkCache networkCache) {
    networkCache.createSwitch(NetworkTopologyConstants.sw1);
    networkCache.createSwitch(NetworkTopologyConstants.sw2);
    networkCache.createSwitch(NetworkTopologyConstants.sw3);
    networkCache.createSwitch(NetworkTopologyConstants.sw4);
    networkCache.createSwitch(NetworkTopologyConstants.sw5);
    networkCache.createOrUpdateIsl(new IslInfoData(NetworkTopologyConstants.isl12));
    networkCache.createOrUpdateIsl(new IslInfoData(NetworkTopologyConstants.isl21));
    networkCache.createOrUpdateIsl(new IslInfoData(NetworkTopologyConstants.isl24));
    networkCache.createOrUpdateIsl(new IslInfoData(NetworkTopologyConstants.isl42));
    networkCache.createOrUpdateIsl(new IslInfoData(NetworkTopologyConstants.isl52));
    networkCache.createOrUpdateIsl(new IslInfoData(NetworkTopologyConstants.isl25));
    networkCache.createOrUpdateIsl(new IslInfoData(NetworkTopologyConstants.isl53));
    networkCache.createOrUpdateIsl(new IslInfoData(NetworkTopologyConstants.isl35));
    networkCache.createOrUpdateIsl(new IslInfoData(NetworkTopologyConstants.isl54));
    networkCache.createOrUpdateIsl(new IslInfoData(NetworkTopologyConstants.isl45));
}
Also used : IslInfoData(org.openkilda.messaging.info.event.IslInfoData)

Aggregations

IslInfoData (org.openkilda.messaging.info.event.IslInfoData)51 PathNode (org.openkilda.messaging.info.event.PathNode)29 Test (org.junit.Test)25 Endpoint (org.openkilda.wfm.share.model.Endpoint)12 SwitchId (org.openkilda.model.SwitchId)10 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)9 Isl (org.openkilda.model.Isl)9 InfoMessage (org.openkilda.messaging.info.InfoMessage)8 ArrayList (java.util.ArrayList)6 When (cucumber.api.java.en.When)5 IOException (java.io.IOException)5 InfoData (org.openkilda.messaging.info.InfoData)5 Switch (org.openkilda.model.Switch)5 Then (cucumber.api.java.en.Then)4 List (java.util.List)4 CommandMessage (org.openkilda.messaging.command.CommandMessage)4 Comparator (java.util.Comparator)3 Collectors (java.util.stream.Collectors)3 Message (org.openkilda.messaging.Message)3 CacheException (org.openkilda.messaging.error.CacheException)3