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