Search in sources :

Example 1 with Isl

use of org.openkilda.topology.domain.Isl in project open-kilda by telstra.

the class IslServiceImplTest method discoverBidirectionalIsl.

@Test
public void discoverBidirectionalIsl() 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(10L, list, 10000000L);
    IslInfoData reverseIsl = new IslInfoData(20L, Lists.reverse(list), 10000000L);
    islService.discoverLink(forwardIsl);
    islService.discoverLink(reverseIsl);
    Isl isl = islService.getLink(forwardIsl);
    assertNotNull(isl);
    assertEquals(10L, isl.getLatency());
    isl = islService.getLink(reverseIsl);
    assertNotNull(isl);
    assertEquals(20L, 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)

Example 2 with Isl

use of org.openkilda.topology.domain.Isl in project open-kilda by telstra.

the class FlowServiceImpl method buildFlow.

/**
 * Creates flow for further saving in database.
 *
 * @return {@link ImmutablePair} of direct and reverse {@link Flow} instances
 */
private Flow buildFlow(final List<Isl> path, final Switch source, final Switch destination, final FlowPayload payload, final int transitVlanId, final long cookie) {
    List<String> pathToStore = new ArrayList<>(path.size() + 1);
    pathToStore.add(payload.getSource().getSwitchId());
    for (Isl isl : path) {
        pathToStore.add(isl.getDestinationSwitch());
    }
    Flow flow = new Flow(source, destination, payload.getId(), cookie, pathToStore, payload.getMaximumBandwidth(), payload.getSource().getSwitchId(), payload.getSource().getPortId(), payload.getSource().getVlanId(), payload.getDestination().getSwitchId(), payload.getDestination().getPortId(), payload.getDestination().getVlanId(), payload.getDescription(), getTime(), transitVlanId);
    logger.debug("Flow prepared: flow={}", flow);
    return flow;
}
Also used : Isl(org.openkilda.topology.domain.Isl) ArrayList(java.util.ArrayList) Flow(org.openkilda.topology.domain.Flow)

Example 3 with Isl

use of org.openkilda.topology.domain.Isl in project open-kilda by telstra.

the class IslServiceImpl method discoverLink.

/**
 * {@inheritDoc}
 */
@Override
public void discoverLink(final IslInfoData data) {
    logger.debug("Isl discover: isl={}", data);
    PathNode sourceNode = data.getPath().get(0);
    PathNode destinationNode = data.getPath().get(1);
    Isl isl = islRepository.findIsl(sourceNode.getSwitchId(), sourceNode.getPortNo(), destinationNode.getSwitchId(), destinationNode.getPortNo());
    logger.debug("Isl relationship found: {}", isl);
    if (isl == null) {
        Switch sourceSwitch = switchRepository.findByName(sourceNode.getSwitchId());
        Switch destinationSwitch = switchRepository.findByName(destinationNode.getSwitchId());
        if (sourceSwitch == null || destinationSwitch == null) {
            logger.error("Could not find switch: source={}, destination={}", sourceSwitch, destinationSwitch);
            return;
        }
        isl = new Isl(sourceSwitch, destinationSwitch, sourceNode.getSwitchId(), sourceNode.getPortNo(), destinationNode.getSwitchId(), destinationNode.getPortNo(), data.getLatency(), data.getSpeed(), 0L);
        // TODO: replace queries on Spring auto generated
        // islRepository.save(isl);
        logger.debug("Isl relationship create: isl={}", isl);
        islRepository.creteIsl(sourceSwitch.getName(), destinationSwitch.getName(), sourceNode.getSwitchId(), sourceNode.getPortNo(), destinationNode.getSwitchId(), destinationNode.getPortNo(), data.getLatency(), data.getSpeed(), 0L);
    } else {
        islRepository.updateLatency(sourceNode.getSwitchId(), sourceNode.getPortNo(), destinationNode.getSwitchId(), destinationNode.getPortNo(), data.getLatency());
        logger.debug("Isl relationship update: latency={}", data.getLatency());
    }
}
Also used : Isl(org.openkilda.topology.domain.Isl) Switch(org.openkilda.topology.domain.Switch) PathNode(org.openkilda.messaging.info.event.PathNode)

Example 4 with Isl

use of org.openkilda.topology.domain.Isl in project open-kilda by telstra.

the class IslServiceImpl method dropLink.

/**
 * {@inheritDoc}
 */
@Override
public void dropLink(final IslInfoData data) {
    logger.debug("Isl drop: isl={}", data);
    PathNode sourceNode = data.getPath().get(0);
    PathNode destinationNode = data.getPath().get(1);
    Switch sourceSwitch = switchRepository.findByName(sourceNode.getSwitchId());
    Switch destinationSwitch = switchRepository.findByName(destinationNode.getSwitchId());
    if (sourceSwitch == null || destinationSwitch == null) {
        logger.error("Could not find switch: source={}, destination={}", sourceSwitch, destinationSwitch);
        return;
    }
    Isl isl = islRepository.findIsl(sourceNode.getSwitchId(), sourceNode.getPortNo(), destinationNode.getSwitchId(), destinationNode.getPortNo());
    logger.debug("Isl relationship found: {}", isl);
    if (isl == null) {
        throw new MessageException(ErrorType.NOT_FOUND, System.currentTimeMillis());
    }
    // TODO: replace queries on Spring auto generated
    // islRepository.delete(isl);
    islRepository.deleteIsl(sourceNode.getSwitchId(), sourceNode.getPortNo(), destinationNode.getSwitchId(), destinationNode.getPortNo());
    logger.debug("Isl delete relationship: isl={}", isl);
}
Also used : Isl(org.openkilda.topology.domain.Isl) Switch(org.openkilda.topology.domain.Switch) MessageException(org.openkilda.messaging.error.MessageException) PathNode(org.openkilda.messaging.info.event.PathNode)

Example 5 with Isl

use of org.openkilda.topology.domain.Isl 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

Isl (org.openkilda.topology.domain.Isl)11 ArrayList (java.util.ArrayList)7 PathNode (org.openkilda.messaging.info.event.PathNode)7 Test (org.junit.Test)4 IslInfoData (org.openkilda.messaging.info.event.IslInfoData)4 Switch (org.openkilda.topology.domain.Switch)4 MessageException (org.openkilda.messaging.error.MessageException)2 Flow (org.openkilda.topology.domain.Flow)2 HashSet (java.util.HashSet)1 CommandMessage (org.openkilda.messaging.command.CommandMessage)1 Node (org.openkilda.topology.model.Node)1 Topology (org.openkilda.topology.model.Topology)1