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++;
}
}
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);
}
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());
}
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()));
}
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;
}
Aggregations