Search in sources :

Example 11 with SwitchInfoData

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

the class TopologyEventsBasicTest method links_are_added_between_the_new_switch_and_its_neighbor.

@When("^links are added between the new switch and its neighbor$")
public void links_are_added_between_the_new_switch_and_its_neighbor() throws Exception {
    List<IslInfoData> links = LinksUtils.dumpLinks();
    List<SwitchInfoData> switches = SwitchesUtils.dumpSwitches();
    SwitchInfoData switchWithoutLinks = switches.stream().filter(sw -> links.stream().anyMatch(isl -> isLinkBelongToSwitch(sw.getSwitchId(), isl))).findAny().orElseThrow(() -> new IllegalStateException("At least one switch should exist"));
    SwitchInfoData latestConnectedSwitch = switches.stream().sorted(Comparator.comparing(SwitchInfoData::getSwitchId).reversed()).findFirst().get();
    assertTrue(LinksUtils.addLink(getSwitchName(switchWithoutLinks.getSwitchId()), getSwitchName(latestConnectedSwitch.getSwitchId())));
    assertTrue(LinksUtils.addLink(getSwitchName(switchWithoutLinks.getSwitchId()), getSwitchName(latestConnectedSwitch.getSwitchId())));
    TimeUnit.SECONDS.sleep(1);
}
Also used : IntStream(java.util.stream.IntStream) StringUtils(org.apache.commons.lang.StringUtils) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) SwitchState(org.openkilda.messaging.info.event.SwitchState) LinksUtils(org.openkilda.LinksUtils) Assert.assertTrue(org.junit.Assert.assertTrue) IslChangeType(org.openkilda.messaging.info.event.IslChangeType) PathNode(org.openkilda.messaging.info.event.PathNode) Collectors(java.util.stream.Collectors) TestTopologyBuilder(org.openkilda.topo.builders.TestTopologyBuilder) NumberUtils(org.apache.commons.lang.math.NumberUtils) Assert.assertThat(org.junit.Assert.assertThat) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Matchers.is(org.hamcrest.Matchers.is) SwitchesUtils(org.openkilda.SwitchesUtils) PendingException(cucumber.api.PendingException) Comparator(java.util.Comparator) Then(cucumber.api.java.en.Then) When(cucumber.api.java.en.When) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) When(cucumber.api.java.en.When)

Example 12 with SwitchInfoData

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

the class NetworkCache method getIslSwitches.

/**
 * Gets {@link SwitchInfoData} instances which are incident nodes for specified {@link IslInfoData} instance.
 *
 * @param isl {@link IslInfoData} instance
 * @return {@link EndpointPair} of {@link SwitchInfoData} instances
 * @throws CacheException if {@link SwitchInfoData} instances for {@link IslInfoData} instance do not exist
 */
private EndpointPair<SwitchInfoData> getIslSwitches(IslInfoData isl) throws CacheException {
    String srcSwitch = isl.getPath().get(0).getSwitchId();
    if (srcSwitch == null) {
        throw new CacheException(ErrorType.PARAMETERS_INVALID, "Can not get isl nodes", "Source switch not specified");
    }
    SwitchInfoData startNode = getSwitch(srcSwitch);
    String dstSwitch = isl.getPath().get(1).getSwitchId();
    if (dstSwitch == null) {
        throw new CacheException(ErrorType.PARAMETERS_INVALID, "Can not get isl nodes", "Destination switch not specified");
    }
    SwitchInfoData endNode = getSwitch(dstSwitch);
    return EndpointPair.ordered(startNode, endNode);
}
Also used : CacheException(org.openkilda.messaging.error.CacheException) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData)

Example 13 with SwitchInfoData

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

the class NetworkCache method updateSwitch.

/**
 * Updates {@link SwitchInfoData} instance.
 *
 * @param newSwitch {@link SwitchInfoData} instance
 * @return {@link SwitchInfoData} instance before update
 * @throws CacheException if {@link SwitchInfoData} instance with specified id does not exist
 */
public SwitchInfoData updateSwitch(SwitchInfoData newSwitch) throws CacheException {
    String switchId = newSwitch.getSwitchId();
    logger.debug("Update {} switch with {} parameters", switchId, newSwitch);
    SwitchInfoData oldSwitch = switchPool.remove(switchId);
    if (oldSwitch == null) {
        throw new CacheException(ErrorType.NOT_FOUND, "Can not update switch", String.format("Switch %s not found", switchId));
    }
    newSwitch.copyTimeTag(oldSwitch);
    newSwitch.setUpdatedInCacheNow();
    network.removeNode(oldSwitch);
    network.addNode(newSwitch);
    switchPool.put(switchId, newSwitch);
    return newSwitch;
}
Also used : CacheException(org.openkilda.messaging.error.CacheException) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData)

Example 14 with SwitchInfoData

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

the class NetworkCache method getIslsBySwitch.

/**
 * Gets all {@link IslInfoData} instances which start or end node is specified {@link SwitchInfoData} instance.
 *
 * @param switchId {@link SwitchInfoData} instance id
 * @return {@link Set} of {@link IslInfoData} instances
 * @throws CacheException if {@link SwitchInfoData} instance with specified id does not exists
 */
public Set<IslInfoData> getIslsBySwitch(String switchId) throws CacheException {
    logger.debug("Get all isls incident switch {}", switchId);
    SwitchInfoData node = getSwitch(switchId);
    return network.incidentEdges(node);
}
Also used : SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData)

Example 15 with SwitchInfoData

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

the class NetworkCache method updateIsl.

/**
 * Updates {@link IslInfoData} instance.
 *
 * @param isl new {@link IslInfoData} instance
 * @return {@link IslInfoData} instance previously associated with {@link IslInfoData} instance id or null otherwise
 * @throws CacheException if {@link SwitchInfoData} related to {@link IslInfoData} instance do not exist
 */
public IslInfoData updateIsl(IslInfoData isl) throws CacheException {
    String islId = isl.getId();
    logger.debug("Update {} isl with {} parameters", islId, isl);
    IslInfoData oldIsl = islPool.get(islId);
    network.removeEdge(oldIsl);
    isl.copyTimeTag(oldIsl);
    isl.setUpdatedInCacheNow();
    EndpointPair<SwitchInfoData> nodes = getIslSwitches(isl);
    network.addEdge(nodes.source(), nodes.target(), isl);
    return islPool.put(islId, isl);
}
Also used : IslInfoData(org.openkilda.messaging.info.event.IslInfoData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData)

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