use of org.openkilda.messaging.info.event.SwitchInfoData in project open-kilda by telstra.
the class TopologyEventsBasicTest method links_are_added_between_the_new_switch_and_its_neighbor.
@When("^links are added between the new switch and its neighbor$")
public void links_are_added_between_the_new_switch_and_its_neighbor() throws Exception {
List<IslInfoData> links = LinksUtils.dumpLinks();
List<SwitchInfoData> switches = SwitchesUtils.dumpSwitches();
SwitchInfoData switchWithoutLinks = switches.stream().filter(sw -> links.stream().anyMatch(isl -> isLinkBelongToSwitch(sw.getSwitchId(), isl))).findAny().orElseThrow(() -> new IllegalStateException("At least one switch should exist"));
SwitchInfoData latestConnectedSwitch = switches.stream().sorted(Comparator.comparing(SwitchInfoData::getSwitchId).reversed()).findFirst().get();
assertTrue(LinksUtils.addLink(getSwitchName(switchWithoutLinks.getSwitchId()), getSwitchName(latestConnectedSwitch.getSwitchId())));
assertTrue(LinksUtils.addLink(getSwitchName(switchWithoutLinks.getSwitchId()), getSwitchName(latestConnectedSwitch.getSwitchId())));
TimeUnit.SECONDS.sleep(1);
}
use of org.openkilda.messaging.info.event.SwitchInfoData in project open-kilda by telstra.
the class NetworkCache method getIslSwitches.
/**
* Gets {@link SwitchInfoData} instances which are incident nodes for specified {@link IslInfoData} instance.
*
* @param isl {@link IslInfoData} instance
* @return {@link EndpointPair} of {@link SwitchInfoData} instances
* @throws CacheException if {@link SwitchInfoData} instances for {@link IslInfoData} instance do not exist
*/
private EndpointPair<SwitchInfoData> getIslSwitches(IslInfoData isl) throws CacheException {
String srcSwitch = isl.getPath().get(0).getSwitchId();
if (srcSwitch == null) {
throw new CacheException(ErrorType.PARAMETERS_INVALID, "Can not get isl nodes", "Source switch not specified");
}
SwitchInfoData startNode = getSwitch(srcSwitch);
String dstSwitch = isl.getPath().get(1).getSwitchId();
if (dstSwitch == null) {
throw new CacheException(ErrorType.PARAMETERS_INVALID, "Can not get isl nodes", "Destination switch not specified");
}
SwitchInfoData endNode = getSwitch(dstSwitch);
return EndpointPair.ordered(startNode, endNode);
}
use of org.openkilda.messaging.info.event.SwitchInfoData in project open-kilda by telstra.
the class NetworkCache method updateSwitch.
/**
* Updates {@link SwitchInfoData} instance.
*
* @param newSwitch {@link SwitchInfoData} instance
* @return {@link SwitchInfoData} instance before update
* @throws CacheException if {@link SwitchInfoData} instance with specified id does not exist
*/
public SwitchInfoData updateSwitch(SwitchInfoData newSwitch) throws CacheException {
String switchId = newSwitch.getSwitchId();
logger.debug("Update {} switch with {} parameters", switchId, newSwitch);
SwitchInfoData oldSwitch = switchPool.remove(switchId);
if (oldSwitch == null) {
throw new CacheException(ErrorType.NOT_FOUND, "Can not update switch", String.format("Switch %s not found", switchId));
}
newSwitch.copyTimeTag(oldSwitch);
newSwitch.setUpdatedInCacheNow();
network.removeNode(oldSwitch);
network.addNode(newSwitch);
switchPool.put(switchId, newSwitch);
return newSwitch;
}
use of org.openkilda.messaging.info.event.SwitchInfoData in project open-kilda by telstra.
the class NetworkCache method getIslsBySwitch.
/**
* Gets all {@link IslInfoData} instances which start or end node is specified {@link SwitchInfoData} instance.
*
* @param switchId {@link SwitchInfoData} instance id
* @return {@link Set} of {@link IslInfoData} instances
* @throws CacheException if {@link SwitchInfoData} instance with specified id does not exists
*/
public Set<IslInfoData> getIslsBySwitch(String switchId) throws CacheException {
logger.debug("Get all isls incident switch {}", switchId);
SwitchInfoData node = getSwitch(switchId);
return network.incidentEdges(node);
}
use of org.openkilda.messaging.info.event.SwitchInfoData in project open-kilda by telstra.
the class NetworkCache method updateIsl.
/**
* Updates {@link IslInfoData} instance.
*
* @param isl new {@link IslInfoData} instance
* @return {@link IslInfoData} instance previously associated with {@link IslInfoData} instance id or null otherwise
* @throws CacheException if {@link SwitchInfoData} related to {@link IslInfoData} instance do not exist
*/
public IslInfoData updateIsl(IslInfoData isl) throws CacheException {
String islId = isl.getId();
logger.debug("Update {} isl with {} parameters", islId, isl);
IslInfoData oldIsl = islPool.get(islId);
network.removeEdge(oldIsl);
isl.copyTimeTag(oldIsl);
isl.setUpdatedInCacheNow();
EndpointPair<SwitchInfoData> nodes = getIslSwitches(isl);
network.addEdge(nodes.source(), nodes.target(), isl);
return islPool.put(islId, isl);
}
Aggregations