Search in sources :

Example 6 with Isl

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

the class IslServiceImplTest method discoverIsl.

@Test
public void discoverIsl() 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());
}
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 7 with Isl

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

the class IslServiceImplTest method dropIsl.

@Test
public void dropIsl() 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());
    islService.dropLink(forwardIsl);
    isl = islService.getLink(forwardIsl);
    assertNull(isl);
}
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 8 with Isl

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

the class FlowServiceImpl method createFlow.

/**
 * {@inheritDoc}
 */
@Override
public Set<CommandMessage> createFlow(final FlowPayload payload, final String correlationId) {
    Switch source = switchRepository.findByName(payload.getSource().getSwitchId());
    Switch destination = switchRepository.findByName(payload.getDestination().getSwitchId());
    if (source == null || destination == null) {
        logger.error("Switches not found: source={}, destination={}", payload.getSource().getSwitchId(), payload.getDestination().getSwitchId());
        throw new MessageException(ErrorType.NOT_FOUND, System.currentTimeMillis());
    }
    List<Isl> path = islRepository.getPath(source.getName(), destination.getName());
    if (path == null || path.isEmpty()) {
        logger.error("Path not found: source={}, destination={}", payload.getSource().getSwitchId(), payload.getDestination().getSwitchId());
        throw new MessageException(ErrorType.NOT_FOUND, System.currentTimeMillis());
    }
    List<Isl> sortedPath = sortPath(source.getName(), path);
    logger.debug("Path found: {}", sortedPath);
    int directVlanId = transitVlanIdPool.allocate();
    int reverseVlanId = transitVlanIdPool.allocate();
    long cookie = getCookie();
    Flow direct = buildFlow(path, source, destination, payload, directVlanId, cookie | DIRECT_FLOW_COOKIE);
    Flow reverse = buildFlow(path, destination, source, payload, reverseVlanId, cookie | REVERSE_FLOW_COOKIE);
    flowRepository.save(direct);
    logger.debug("Flow stored: flow={}", direct);
    flowRepository.save(reverse);
    logger.debug("Flow stored: flow={}", reverse);
    Set<CommandMessage> response = new HashSet<>();
    response.addAll(direct.getInstallationCommands(sortedPath, correlationId));
    response.addAll(reverse.getInstallationCommands(sortedPath, correlationId));
    logger.debug("Flows create command message list: {}", response);
    return response;
}
Also used : Isl(org.openkilda.topology.domain.Isl) Switch(org.openkilda.topology.domain.Switch) MessageException(org.openkilda.messaging.error.MessageException) Flow(org.openkilda.topology.domain.Flow) CommandMessage(org.openkilda.messaging.command.CommandMessage) HashSet(java.util.HashSet)

Example 9 with Isl

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

the class FlowServiceImpl method sortPath.

/**
 * Sorts path between two switches.
 *
 * @param source source switch datapath id
 * @param links  list of {@link Isl} instances
 * @return sorted path of {@link Isl} instances
 */
private static List<Isl> sortPath(String source, List<Isl> links) {
    Map<String, Isl> map = links.stream().collect(toMap(Isl::getSourceSwitch, Function.identity()));
    List<Isl> path = new ArrayList<>(links.size());
    Isl first = map.get(source);
    path.add(first);
    Isl next = map.get(first.getDestinationSwitch());
    while (next != null) {
        path.add(next);
        next = map.get(next.getDestinationSwitch());
    }
    return path;
}
Also used : Isl(org.openkilda.topology.domain.Isl) ArrayList(java.util.ArrayList)

Example 10 with Isl

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

the class IslServiceImpl method getLink.

/**
 * {@inheritDoc}
 */
@Override
public Isl getLink(final IslInfoData data) {
    logger.debug("Isl get: 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);
    return isl;
}
Also used : Isl(org.openkilda.topology.domain.Isl) PathNode(org.openkilda.messaging.info.event.PathNode)

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