Search in sources :

Example 1 with Switch

use of org.openkilda.topology.domain.Switch 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 2 with Switch

use of org.openkilda.topology.domain.Switch 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 3 with Switch

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

the class SwitchServiceImpl method add.

/**
 * {@inheritDoc}
 */
@Override
public Switch add(final SwitchInfoData data) {
    String name = data.getSwitchId();
    String state = SwitchStateType.INACTIVE.toString().toLowerCase();
    logger.debug("Switch adding: switch-id={}", name);
    Switch sw = switchRepository.findByName(name);
    if (sw != null) {
        throw new MessageException(ErrorType.ALREADY_EXISTS, System.currentTimeMillis());
    }
    sw = new Switch(name, state, data.getAddress(), data.getHostname(), data.getDescription());
    sw.setLabels(state, data.getDescription());
    switchRepository.save(sw);
    return sw;
}
Also used : Switch(org.openkilda.topology.domain.Switch) MessageException(org.openkilda.messaging.error.MessageException)

Example 4 with Switch

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

the class SwitchServiceImpl method remove.

/**
 * {@inheritDoc}
 */
@Override
public Switch remove(final SwitchInfoData data) {
    String name = data.getSwitchId();
    logger.debug("Switch removing: switch-id={}", name);
    Switch sw = switchRepository.findByName(name);
    if (sw == null) {
        throw new MessageException(ErrorType.NOT_FOUND, System.currentTimeMillis());
    }
    switchRepository.delete(sw);
    return sw;
}
Also used : Switch(org.openkilda.topology.domain.Switch) MessageException(org.openkilda.messaging.error.MessageException)

Example 5 with Switch

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

the class SwitchServiceImplTest method add.

@Test
@Transactional
public void add() throws Exception {
    SwitchInfoData data = new SwitchInfoData(switchId, SwitchEventType.ADDED, address, name, description);
    Switch sw = switchService.add(data);
    assertEquals(sw.getName(), switchId);
    assertEquals(sw.getState(), SwitchStateType.INACTIVE.toString().toLowerCase());
}
Also used : Switch(org.openkilda.topology.domain.Switch) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Switch (org.openkilda.topology.domain.Switch)11 MessageException (org.openkilda.messaging.error.MessageException)6 Isl (org.openkilda.topology.domain.Isl)4 Test (org.junit.Test)3 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)3 Transactional (org.springframework.transaction.annotation.Transactional)3 PathNode (org.openkilda.messaging.info.event.PathNode)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 CommandMessage (org.openkilda.messaging.command.CommandMessage)1 Flow (org.openkilda.topology.domain.Flow)1 Node (org.openkilda.topology.model.Node)1 Topology (org.openkilda.topology.model.Topology)1