Search in sources :

Example 26 with SwitchInfoData

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

the class SpeakerBoltTest method testAddSwitchValues.

@Test
public void testAddSwitchValues() throws Exception {
    List<Values> values = speakerBolt.addSwitch(switchMessage);
    assertEquals(3, values.size());
    int count = 0;
    for (Values value : values) {
        InfoMessage infoMessage = mapper.readValue((String) value.get(1), InfoMessage.class);
        if (count < 2) {
            assertThat(infoMessage.getData(), instanceOf(SwitchInfoData.class));
            SwitchInfoData sw = (SwitchInfoData) infoMessage.getData();
            assertEquals("00:00:" + dpid, sw.getSwitchId());
        } else {
            assertThat(infoMessage.getData(), instanceOf(PortInfoData.class));
            PortInfoData port = (PortInfoData) infoMessage.getData();
            assertEquals("00:00:" + dpid, port.getSwitchId());
            if (port.getPortNo() == localLinkPort) {
                assertEquals(PortChangeType.UP, port.getState());
            } else {
                assertEquals(PortChangeType.DOWN, port.getState());
            }
        }
        count++;
    }
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) Values(org.apache.storm.tuple.Values) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) Test(org.junit.Test)

Example 27 with SwitchInfoData

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

the class OFELinkBoltFloodTest method warmBoltOnHighLoadedTopic.

@Test(timeout = 5000 * 60)
public void warmBoltOnHighLoadedTopic() throws Exception {
    topology = new OFEventWFMTopology(makeLaunchEnvironment());
    teConsumer = new TestKafkaConsumer(topology.getConfig().getKafkaTopoEngTopic(), kafkaProperties(UUID.nameUUIDFromBytes(Destination.TOPOLOGY_ENGINE.toString().getBytes()).toString()));
    teConsumer.start();
    // Size of messages in topic before bolt start
    final int floodSize = 100000;
    SwitchInfoData data = new SwitchInfoData("switchId", SwitchState.ADDED, "address", "hostname", "description", "controller");
    InfoMessage message = new InfoMessage(data, System.currentTimeMillis(), UUID.randomUUID().toString());
    // Floooding
    sendMessages(message, topology.getConfig().getKafkaTopoDiscoTopic(), floodSize);
    StormTopology stormTopology = topology.createTopology();
    Config config = stormConfig();
    cluster.submitTopology(OFELinkBoltFloodTest.class.getSimpleName(), config, stormTopology);
    NetworkInfoData dump = new NetworkInfoData("test", Collections.emptySet(), Collections.emptySet(), Collections.emptySet(), Collections.emptySet());
    InfoMessage info = new InfoMessage(dump, 0, DEFAULT_CORRELATION_ID, Destination.WFM);
    String request = objectMapper.writeValueAsString(info);
    // Send DumpMessage to topic with offset floodSize+1.
    kProducer.pushMessage(topology.getConfig().getKafkaTopoDiscoTopic(), request);
    // Wait all messages
    int pooled = 0;
    while (pooled < floodSize) {
        if (teConsumer.pollMessage() != null)
            ++pooled;
    }
    assertEquals(floodSize, pooled);
}
Also used : NetworkInfoData(org.openkilda.messaging.info.discovery.NetworkInfoData) TestKafkaConsumer(org.openkilda.wfm.topology.TestKafkaConsumer) InfoMessage(org.openkilda.messaging.info.InfoMessage) Config(org.apache.storm.Config) StormTopology(org.apache.storm.generated.StormTopology) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) AbstractStormTest(org.openkilda.wfm.AbstractStormTest) Test(org.junit.Test)

Example 28 with SwitchInfoData

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

the class OFELinkBoltTest method cacheLoadCheck.

/**
 * Part of warm mechanism checks. That test verifies appropriately unpack and fill inner
 * cache after getting network dump information from FL.
 */
@Test
public void cacheLoadCheck() throws IOException {
    // Send cache data and verify is inner state is ok
    SwitchInfoData sw1 = new SwitchInfoData("sw1", SwitchState.ADDED, "127.0.0.1", "localhost", "test switch", "kilda");
    SwitchInfoData sw2 = new SwitchInfoData("sw2", SwitchState.ADDED, "127.0.0.1", "localhost", "test switch", "kilda");
    PortInfoData sw1Port1 = new PortInfoData(sw1.getSwitchId(), 1, null, UP);
    PortInfoData sw2Port1 = new PortInfoData(sw2.getSwitchId(), 1, null, UP);
    NetworkInfoData dump = new NetworkInfoData("test", new HashSet<>(Arrays.asList(sw1, sw2)), new HashSet<>(Arrays.asList(sw1Port1, sw2Port1)), Collections.emptySet(), Collections.emptySet());
    InfoMessage info = new InfoMessage(dump, 0, DEFAULT_CORRELATION_ID, Destination.WFM);
    String request = objectMapper.writeValueAsString(info);
    Tuple dumpTuple = new TupleImpl(context, new Values(request), TASK_ID_BOLT, STREAM_ID_INPUT);
    bolt.doWork(dumpTuple);
    List<DiscoveryNode> discoveryQueue = bolt.getDiscoveryQueue();
    // I don't check discoveryQueue contents because that should be done in a test for
    // handleSwitchEvent and handlePortEvent.
    assertEquals(2, discoveryQueue.size());
}
Also used : NetworkInfoData(org.openkilda.messaging.info.discovery.NetworkInfoData) DiscoveryNode(org.openkilda.messaging.model.DiscoveryNode) InfoMessage(org.openkilda.messaging.info.InfoMessage) Values(org.apache.storm.tuple.Values) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) TupleImpl(org.apache.storm.tuple.TupleImpl) Tuple(org.apache.storm.tuple.Tuple) AbstractStormTest(org.openkilda.wfm.AbstractStormTest) Test(org.junit.Test)

Example 29 with SwitchInfoData

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

the class PathComputerMock method getPath.

@Override
public ImmutablePair<PathInfoData, PathInfoData> getPath(Flow flow, Strategy strategy) {
    /*
         * TODO: Implement other strategies? Default is HOPS ...
         * TODO: Is PathComputerMock necessary, since we can embed Neo4J?
         */
    SwitchInfoData source = network.nodes().stream().filter(sw -> sw.getSwitchId().equals(flow.getSourceSwitch())).findFirst().orElse(null);
    if (source == null) {
        throw new CacheException(ErrorType.NOT_FOUND, "Can not find path", String.format("Error: No node found source=%s", flow.getSourceSwitch()));
    }
    SwitchInfoData destination = network.nodes().stream().filter(sw -> sw.getSwitchId().equals(flow.getDestinationSwitch())).findFirst().orElse(null);
    if (destination == null) {
        throw new CacheException(ErrorType.NOT_FOUND, "Can not find path", String.format("Error: No node found destination=%s", flow.getDestinationSwitch()));
    }
    return new ImmutablePair<>(path(source, destination, flow.getBandwidth()), path(destination, source, flow.getBandwidth()));
}
Also used : ImmutablePair(org.openkilda.messaging.model.ImmutablePair) CacheException(org.openkilda.messaging.error.CacheException) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData)

Example 30 with SwitchInfoData

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

SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)38 Test (org.junit.Test)11 InfoMessage (org.openkilda.messaging.info.InfoMessage)9 IslInfoData (org.openkilda.messaging.info.event.IslInfoData)9 CacheException (org.openkilda.messaging.error.CacheException)8 CommandMessage (org.openkilda.messaging.command.CommandMessage)7 PathNode (org.openkilda.messaging.info.event.PathNode)6 PortInfoData (org.openkilda.messaging.info.event.PortInfoData)5 Transactional (org.springframework.transaction.annotation.Transactional)5 IOException (java.io.IOException)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 InfoData (org.openkilda.messaging.info.InfoData)4 NetworkInfoData (org.openkilda.messaging.info.discovery.NetworkInfoData)4 AbstractStormTest (org.openkilda.wfm.AbstractStormTest)4 Then (cucumber.api.java.en.Then)3 When (cucumber.api.java.en.When)3 Comparator (java.util.Comparator)3 Switch (org.openkilda.topology.domain.Switch)3 PendingException (cucumber.api.PendingException)2