Search in sources :

Example 11 with IslInfoData

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

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

the class NetworkCache method getIsl.

/**
 * Get {@link IslInfoData} instance.
 *
 * @param islId {@link IslInfoData} instance id
 * @return {@link IslInfoData} instance with specified {@link IslInfoData} instance id
 * @throws CacheException if {@link IslInfoData} instance with specified id does not exist
 */
public IslInfoData getIsl(String islId) throws CacheException {
    logger.debug("Get {} isl", islId);
    IslInfoData isl = islPool.get(islId);
    if (isl == null) {
        throw new CacheException(ErrorType.NOT_FOUND, "Can not get isl", String.format("Isl %s not found", islId));
    }
    return islPool.get(islId);
}
Also used : CacheException(org.openkilda.messaging.error.CacheException) IslInfoData(org.openkilda.messaging.info.event.IslInfoData)

Example 13 with IslInfoData

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

the class NetworkCache method deleteIsl.

/**
 * Deletes {@link IslInfoData} instance.
 *
 * @param islId {@link IslInfoData} instance id
 * @return removed {@link IslInfoData} instance
 * @throws CacheException if {@link IslInfoData} instance with specified id does not exist
 */
public IslInfoData deleteIsl(String islId) throws CacheException {
    logger.debug("Delete {} isl", islId);
    IslInfoData isl = islPool.remove(islId);
    if (isl == null) {
        throw new CacheException(ErrorType.NOT_FOUND, "Can not delete isl", String.format("Isl %s not found", islId));
    }
    network.removeEdge(isl);
    return isl;
}
Also used : CacheException(org.openkilda.messaging.error.CacheException) IslInfoData(org.openkilda.messaging.info.event.IslInfoData)

Example 14 with IslInfoData

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

Example 15 with IslInfoData

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

the class IslServiceImplTest method updateLinkLatency.

@Test
public void updateLinkLatency() 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());
    forwardIsl = new IslInfoData(200L, list, 10000000L);
    islService.discoverLink(forwardIsl);
    isl = islService.getLink(forwardIsl);
    assertNotNull(isl);
    assertEquals(200L, 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)

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