Search in sources :

Example 11 with SwitchId

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);
}
Also used : SwitchId(org.openkilda.model.SwitchId)

Example 12 with 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())));
}
Also used : PathId(org.openkilda.model.PathId) DataAdapter(org.openkilda.rulemanager.DataAdapter) PersistenceDataAdapter(org.openkilda.rulemanager.adapter.PersistenceDataAdapter) SwitchId(org.openkilda.model.SwitchId) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow)

Example 13 with SwitchId

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());
}
Also used : SwitchId(org.openkilda.model.SwitchId) DetectConnectedDevices(org.openkilda.model.DetectConnectedDevices) SwitchProperties(org.openkilda.model.SwitchProperties)

Example 14 with SwitchId

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);
    }
}
Also used : PathId(org.openkilda.model.PathId) SpeakerRequestEmitter(org.openkilda.wfm.topology.flowhs.utils.SpeakerRequestEmitter) FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) SwitchId(org.openkilda.model.SwitchId) Flow(org.openkilda.model.Flow)

Example 15 with SwitchId

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");
}
Also used : YFlow(org.openkilda.model.YFlow) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) InstallSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.InstallSpeakerCommandsRequest) SwitchId(org.openkilda.model.SwitchId) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) DeleteSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest)

Aggregations

SwitchId (org.openkilda.model.SwitchId)339 Test (org.junit.Test)149 Flow (org.openkilda.model.Flow)73 Switch (org.openkilda.model.Switch)69 List (java.util.List)59 FlowPath (org.openkilda.model.FlowPath)49 ArrayList (java.util.ArrayList)44 Collectors (java.util.stream.Collectors)37 PathId (org.openkilda.model.PathId)36 PathComputer (org.openkilda.pce.PathComputer)35 Set (java.util.Set)34 YFlow (org.openkilda.model.YFlow)33 Map (java.util.Map)30 GetPathsResult (org.openkilda.pce.GetPathsResult)30 InfoMessage (org.openkilda.messaging.info.InfoMessage)29 String.format (java.lang.String.format)28 HashSet (java.util.HashSet)27 Optional (java.util.Optional)27 Collection (java.util.Collection)26 Collections (java.util.Collections)26