use of org.openkilda.topology.domain.Isl in project open-kilda by telstra.
the class IslServiceImplTest method discoverBidirectionalIsl.
@Test
public void discoverBidirectionalIsl() 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(10L, list, 10000000L);
IslInfoData reverseIsl = new IslInfoData(20L, Lists.reverse(list), 10000000L);
islService.discoverLink(forwardIsl);
islService.discoverLink(reverseIsl);
Isl isl = islService.getLink(forwardIsl);
assertNotNull(isl);
assertEquals(10L, isl.getLatency());
isl = islService.getLink(reverseIsl);
assertNotNull(isl);
assertEquals(20L, isl.getLatency());
}
use of org.openkilda.topology.domain.Isl in project open-kilda by telstra.
the class FlowServiceImpl method buildFlow.
/**
* Creates flow for further saving in database.
*
* @return {@link ImmutablePair} of direct and reverse {@link Flow} instances
*/
private Flow buildFlow(final List<Isl> path, final Switch source, final Switch destination, final FlowPayload payload, final int transitVlanId, final long cookie) {
List<String> pathToStore = new ArrayList<>(path.size() + 1);
pathToStore.add(payload.getSource().getSwitchId());
for (Isl isl : path) {
pathToStore.add(isl.getDestinationSwitch());
}
Flow flow = new Flow(source, destination, payload.getId(), cookie, pathToStore, payload.getMaximumBandwidth(), payload.getSource().getSwitchId(), payload.getSource().getPortId(), payload.getSource().getVlanId(), payload.getDestination().getSwitchId(), payload.getDestination().getPortId(), payload.getDestination().getVlanId(), payload.getDescription(), getTime(), transitVlanId);
logger.debug("Flow prepared: flow={}", flow);
return flow;
}
use of org.openkilda.topology.domain.Isl 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());
}
}
use of org.openkilda.topology.domain.Isl 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);
}
use of org.openkilda.topology.domain.Isl in project open-kilda by telstra.
the class IslServiceImplTest method updateLinkLatency.
@Test
public void updateLinkLatency() 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());
forwardIsl = new IslInfoData(200L, list, 10000000L);
islService.discoverLink(forwardIsl);
isl = islService.getLink(forwardIsl);
assertNotNull(isl);
assertEquals(200L, isl.getLatency());
}
Aggregations