use of org.openkilda.model.SwitchId in project open-kilda by telstra.
the class ControllerToSpeakerProxyService method unicastHsRequest.
public void unicastHsRequest(AbstractMessage message) {
SwitchId switchId = RouterUtils.lookupSwitchId(message);
proxyUnicastRequest(new ProxyHsMessageWrapper(message), switchId);
}
use of org.openkilda.model.SwitchId in project open-kilda by telstra.
the class YFlowRuleManagerProcessingAction method buildYFlowSpeakerData.
private Map<SwitchId, List<SpeakerData>> buildYFlowSpeakerData(YFlow yFlow) {
List<FlowPath> flowPaths = yFlow.getSubFlows().stream().map(YSubFlow::getFlow).map(Flow::getPaths).flatMap(Collection::stream).collect(toList());
Set<SwitchId> switchIds = Sets.newHashSet(yFlow.getSharedEndpoint().getSwitchId(), yFlow.getYPoint(), yFlow.getProtectedPathYPoint());
Set<PathId> pathIds = flowPaths.stream().map(FlowPath::getPathId).collect(Collectors.toSet());
DataAdapter dataAdapter = PersistenceDataAdapter.builder().persistenceManager(persistenceManager).switchIds(switchIds).pathIds(pathIds).build();
return ruleManager.buildRulesForYFlow(flowPaths, dataAdapter).stream().collect(Collectors.groupingBy(SpeakerData::getSwitchId, Collectors.mapping(Function.identity(), toList())));
}
use of org.openkilda.model.SwitchId in project open-kilda by telstra.
the class ResourcesAllocationAction method updateSwitchRelatedFlowProperties.
// TODO: refactor FlowCreate and unify ResourcesAllocationAction with BaseResourceAllocationAction to avoid
// code duplication.
private void updateSwitchRelatedFlowProperties(Flow flow) {
Map<SwitchId, SwitchProperties> switchProperties = LazyMap.lazyMap(new HashMap<>(), switchId -> switchPropertiesRepository.findBySwitchId(switchId).orElse(null));
DetectConnectedDevices.DetectConnectedDevicesBuilder detectConnectedDevices = flow.getDetectConnectedDevices().toBuilder();
SwitchProperties srcSwitchProps = switchProperties.get(flow.getSrcSwitchId());
if (srcSwitchProps != null) {
detectConnectedDevices.srcSwitchLldp(srcSwitchProps.isSwitchLldp());
detectConnectedDevices.srcSwitchArp(srcSwitchProps.isSwitchArp());
}
SwitchProperties destSwitchProps = switchProperties.get(flow.getDestSwitchId());
if (destSwitchProps != null) {
switchProperties.put(flow.getDestSwitchId(), destSwitchProps);
detectConnectedDevices.dstSwitchLldp(destSwitchProps.isSwitchLldp());
detectConnectedDevices.dstSwitchArp(destSwitchProps.isSwitchArp());
}
flow.setDetectConnectedDevices(detectConnectedDevices.build());
}
use of org.openkilda.model.SwitchId in project open-kilda by telstra.
the class EmitUpdateRulesRequestsAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowMirrorPointCreateContext context, FlowMirrorPointCreateFsm stateMachine) {
stateMachine.getCommands().clear();
stateMachine.getPendingCommands().clear();
String flowId = stateMachine.getFlowId();
Flow flow = getFlow(flowId);
Collection<FlowSegmentRequestFactory> commands = buildCommands(stateMachine, flow);
// emitting
PathId flowPathId = stateMachine.getFlowPathId();
SwitchId mirrorSwitchId = stateMachine.getMirrorSwitchId();
FlowMirrorPoints mirrorPoints = flowMirrorPointsRepository.findByPathIdAndSwitchId(flowPathId, mirrorSwitchId).orElse(null);
SpeakerRequestEmitter requestEmitter;
if (mirrorPoints != null && mirrorPoints.getMirrorPaths().isEmpty()) {
requestEmitter = SpeakerRemoveSegmentEmitter.INSTANCE;
} else {
requestEmitter = SpeakerInstallSegmentEmitter.INSTANCE;
}
requestEmitter.emitBatch(stateMachine.getCarrier(), commands, stateMachine.getCommands());
stateMachine.getCommands().forEach((key, value) -> stateMachine.getPendingCommands().put(key, value.getSwitchId()));
if (commands.isEmpty()) {
stateMachine.saveActionToHistory("No need to update rules");
} else {
stateMachine.saveActionToHistory("Commands for updating rules have been sent");
stateMachine.setRulesInstalled(true);
}
}
use of org.openkilda.model.SwitchId in project open-kilda by telstra.
the class UpdateYFlowRulesAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowPathSwapContext context, FlowPathSwapFsm stateMachine) {
String flowId = stateMachine.getFlowId();
Flow flow = getFlow(flowId);
String yFlowId = flow.getYFlowId();
if (yFlowId == null) {
stateMachine.saveActionToHistory("No need to update y-flow rules - it's not a sub-flow");
stateMachine.fire(Event.SKIP_YFLOW_RULES_UPDATE);
return;
}
YFlow yFlow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Y-flow %s not found in persistent storage", yFlowId)));
stateMachine.clearPendingAndRetriedAndFailedCommands();
SwitchId sharedEndpoint = yFlow.getSharedEndpoint().getSwitchId();
InstallSpeakerCommandsRequest installRequest = buildYFlowInstallRequest(sharedEndpoint, stateMachine.getNewPrimaryForwardPath(), stateMachine.getCommandContext());
stateMachine.addInstallSpeakerCommand(installRequest.getCommandId(), installRequest);
DeleteSpeakerCommandsRequest deleteRequest = buildYFlowDeleteRequest(sharedEndpoint, stateMachine.getOldPrimaryForwardPath(), stateMachine.getCommandContext());
stateMachine.addDeleteSpeakerCommand(deleteRequest.getCommandId(), deleteRequest);
// emitting
Stream.of(installRequest, deleteRequest).forEach(command -> {
stateMachine.getCarrier().sendSpeakerRequest(command);
stateMachine.addPendingCommand(command.getCommandId(), command.getSwitchId());
});
stateMachine.saveActionToHistory("Commands for updating y-flow rules have been sent");
}
Aggregations