Search in sources :

Example 6 with Switch

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

the class SwitchServiceImplTest method deactivate.

@Test
@Transactional
public void deactivate() throws Exception {
    SwitchInfoData data = new SwitchInfoData(switchId, SwitchEventType.DEACTIVATED, address, name, description);
    switchService.add(data);
    assertNotNull(switchService.get(switchId));
    switchService.deactivate(data);
    Switch sw = switchService.get(switchId);
    assertEquals(SwitchStateType.INACTIVE.toString().toLowerCase(), sw.getState());
    Iterable<Switch> switches = switchService.dump();
    assertEquals(1, Iterables.size(switches));
}
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)

Example 7 with Switch

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

the class SwitchServiceImplTest method activate.

@Test
@Transactional
public void activate() throws Exception {
    SwitchInfoData data = new SwitchInfoData(switchId, SwitchEventType.ACTIVATED, address, name, description);
    switchService.add(data);
    assertNotNull(switchService.get(switchId));
    switchService.activate(data);
    Switch sw = switchService.get(switchId);
    assertEquals(SwitchStateType.ACTIVE.toString().toLowerCase(), sw.getState());
    Iterable<Switch> switches = switchService.dump();
    assertEquals(1, Iterables.size(switches));
}
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)

Example 8 with Switch

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

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

the class SwitchServiceImpl method deactivate.

/**
 * {@inheritDoc}
 */
@Override
public Switch deactivate(final SwitchInfoData data) {
    String name = data.getSwitchId();
    String state = SwitchStateType.INACTIVE.toString().toLowerCase();
    logger.debug("Switch deactivating: switch-id={}", name);
    Switch sw = switchRepository.findByName(name);
    if (sw == null) {
        throw new MessageException(ErrorType.NOT_FOUND, System.currentTimeMillis());
    }
    sw.setState(state);
    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 10 with Switch

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

the class SwitchServiceImpl method activate.

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

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