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));
}
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));
}
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;
}
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;
}
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;
}
Aggregations