Search in sources :

Example 1 with PathInfoData

use of org.openkilda.messaging.info.event.PathInfoData in project open-kilda by telstra.

the class CrudBolt method handleUpdateRequest.

private void handleUpdateRequest(CommandMessage message, Tuple tuple) throws IOException {
    Flow requestedFlow = ((FlowUpdateRequest) message.getData()).getPayload();
    ImmutablePair<PathInfoData, PathInfoData> path;
    try {
        new FlowValidator(flowCache).checkFlowForEndpointConflicts(requestedFlow);
        path = pathComputer.getPath(requestedFlow, Strategy.COST);
        logger.info("Updated flow path: {}", path);
    } catch (FlowValidationException e) {
        throw new MessageException(message.getCorrelationId(), System.currentTimeMillis(), ErrorType.UPDATE_FAILURE, "Could not update flow", e.getMessage());
    } catch (UnroutablePathException e) {
        throw new MessageException(message.getCorrelationId(), System.currentTimeMillis(), ErrorType.UPDATE_FAILURE, "Could not update flow", "Path was not found");
    }
    ImmutablePair<Flow, Flow> flow = flowCache.updateFlow(requestedFlow, path);
    logger.info("Updated flow: {}", flow);
    FlowInfoData data = new FlowInfoData(requestedFlow.getFlowId(), flow, FlowOperation.UPDATE, message.getCorrelationId());
    InfoMessage infoMessage = new InfoMessage(data, System.currentTimeMillis(), message.getCorrelationId());
    Values topology = new Values(MAPPER.writeValueAsString(infoMessage));
    outputCollector.emit(StreamType.UPDATE.toString(), tuple, topology);
    Values northbound = new Values(new InfoMessage(new FlowResponse(buildFlowResponse(flow)), message.getTimestamp(), message.getCorrelationId(), Destination.NORTHBOUND));
    outputCollector.emit(StreamType.RESPONSE.toString(), tuple, northbound);
}
Also used : FlowUpdateRequest(org.openkilda.messaging.command.flow.FlowUpdateRequest) Values(org.apache.storm.tuple.Values) UnroutablePathException(org.openkilda.pce.provider.UnroutablePathException) Flow(org.openkilda.messaging.model.Flow) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) FlowValidationException(org.openkilda.wfm.topology.flow.validation.FlowValidationException) MessageException(org.openkilda.messaging.error.MessageException) InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowValidator(org.openkilda.wfm.topology.flow.validation.FlowValidator)

Example 2 with PathInfoData

use of org.openkilda.messaging.info.event.PathInfoData in project open-kilda by telstra.

the class CrudBolt method handleRestoreRequest.

private void handleRestoreRequest(CommandMessage message, Tuple tuple) throws IOException {
    ImmutablePair<Flow, Flow> requestedFlow = ((FlowRestoreRequest) message.getData()).getPayload();
    try {
        ImmutablePair<PathInfoData, PathInfoData> path = pathComputer.getPath(requestedFlow.getLeft(), Strategy.COST);
        logger.info("Restored flow path: {}", path);
        ImmutablePair<Flow, Flow> flow;
        if (flowCache.cacheContainsFlow(requestedFlow.getLeft().getFlowId())) {
            flow = flowCache.updateFlow(requestedFlow, path);
        } else {
            flow = flowCache.createFlow(requestedFlow, path);
        }
        logger.info("Restored flow: {}", flow);
        Values topology = new Values(Utils.MAPPER.writeValueAsString(new FlowInfoData(requestedFlow.getLeft().getFlowId(), flow, FlowOperation.UPDATE, message.getCorrelationId())));
        outputCollector.emit(StreamType.UPDATE.toString(), tuple, topology);
    } catch (UnroutablePathException e) {
        throw new MessageException(message.getCorrelationId(), System.currentTimeMillis(), ErrorType.CREATION_FAILURE, "Could not restore flow", "Path was not found");
    }
}
Also used : PathInfoData(org.openkilda.messaging.info.event.PathInfoData) MessageException(org.openkilda.messaging.error.MessageException) Values(org.apache.storm.tuple.Values) FlowRestoreRequest(org.openkilda.messaging.command.flow.FlowRestoreRequest) UnroutablePathException(org.openkilda.pce.provider.UnroutablePathException) Flow(org.openkilda.messaging.model.Flow)

Example 3 with PathInfoData

use of org.openkilda.messaging.info.event.PathInfoData in project open-kilda by telstra.

the class CrudBolt method handleCreateRequest.

private void handleCreateRequest(CommandMessage message, Tuple tuple) throws IOException {
    Flow requestedFlow = ((FlowCreateRequest) message.getData()).getPayload();
    ImmutablePair<PathInfoData, PathInfoData> path;
    try {
        new FlowValidator(flowCache).checkFlowForEndpointConflicts(requestedFlow);
        path = pathComputer.getPath(requestedFlow, Strategy.COST);
        logger.info("Created flow path: {}", path);
    } catch (FlowValidationException e) {
        throw new MessageException(message.getCorrelationId(), System.currentTimeMillis(), ErrorType.CREATION_FAILURE, "Could not create flow", e.getMessage());
    } catch (UnroutablePathException e) {
        throw new MessageException(message.getCorrelationId(), System.currentTimeMillis(), ErrorType.CREATION_FAILURE, "Could not create flow", "Path was not found");
    }
    ImmutablePair<Flow, Flow> flow = flowCache.createFlow(requestedFlow, path);
    logger.info("Created flow: {}", flow);
    FlowInfoData data = new FlowInfoData(requestedFlow.getFlowId(), flow, FlowOperation.CREATE, message.getCorrelationId());
    InfoMessage infoMessage = new InfoMessage(data, System.currentTimeMillis(), message.getCorrelationId());
    Values topology = new Values(MAPPER.writeValueAsString(infoMessage));
    outputCollector.emit(StreamType.CREATE.toString(), tuple, topology);
    Values northbound = new Values(new InfoMessage(new FlowResponse(buildFlowResponse(flow)), message.getTimestamp(), message.getCorrelationId(), Destination.NORTHBOUND));
    outputCollector.emit(StreamType.RESPONSE.toString(), tuple, northbound);
}
Also used : FlowCreateRequest(org.openkilda.messaging.command.flow.FlowCreateRequest) Values(org.apache.storm.tuple.Values) UnroutablePathException(org.openkilda.pce.provider.UnroutablePathException) Flow(org.openkilda.messaging.model.Flow) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) FlowValidationException(org.openkilda.wfm.topology.flow.validation.FlowValidationException) MessageException(org.openkilda.messaging.error.MessageException) InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowValidator(org.openkilda.wfm.topology.flow.validation.FlowValidator)

Example 4 with PathInfoData

use of org.openkilda.messaging.info.event.PathInfoData in project open-kilda by telstra.

the class CrudBolt method handleRerouteRequest.

private void handleRerouteRequest(CommandMessage message, Tuple tuple) throws IOException {
    FlowRerouteRequest request = (FlowRerouteRequest) message.getData();
    Flow requestedFlow = request.getPayload();
    final String flowId = requestedFlow.getFlowId();
    ImmutablePair<Flow, Flow> flow;
    logger.debug("Handling reroute request with correlationId {}", message.getCorrelationId());
    switch(request.getOperation()) {
        case UPDATE:
            flow = flowCache.getFlow(flowId);
            try {
                ImmutablePair<PathInfoData, PathInfoData> path = pathComputer.getPath(flow.getLeft(), Strategy.COST);
                logger.info("Rerouted flow path: {}", path);
                // no need to emit changes if path wasn't changed and flow is active.
                if (!path.getLeft().equals(flow.getLeft().getFlowPath()) || !isFlowActive(flow)) {
                    flow.getLeft().setState(FlowState.DOWN);
                    flow.getRight().setState(FlowState.DOWN);
                    flow = flowCache.updateFlow(flow.getLeft(), path);
                    logger.info("Rerouted flow: {}", flow);
                    FlowInfoData data = new FlowInfoData(flowId, flow, FlowOperation.UPDATE, message.getCorrelationId());
                    InfoMessage infoMessage = new InfoMessage(data, System.currentTimeMillis(), message.getCorrelationId());
                    Values topology = new Values(MAPPER.writeValueAsString(infoMessage));
                    outputCollector.emit(StreamType.UPDATE.toString(), tuple, topology);
                } else {
                    logger.debug("Reroute was unsuccessful: can't find new path");
                }
                logger.debug("Sending response to NB. Correlation id {}", message.getCorrelationId());
                Values response = new Values(new InfoMessage(new FlowPathResponse(flow.left.getFlowPath()), message.getTimestamp(), message.getCorrelationId(), Destination.NORTHBOUND));
                outputCollector.emit(StreamType.RESPONSE.toString(), tuple, response);
            } catch (UnroutablePathException e) {
                flow.getLeft().setState(FlowState.DOWN);
                flow.getRight().setState(FlowState.DOWN);
                throw new MessageException(message.getCorrelationId(), System.currentTimeMillis(), ErrorType.UPDATE_FAILURE, "Could not reroute flow", "Path was not found");
            }
            break;
        case CREATE:
            flow = flowCache.getFlow(flowId);
            logger.info("State flow: {}={}", flow.getLeft().getFlowId(), FlowState.UP);
            flow.getLeft().setState(FlowState.UP);
            flow.getRight().setState(FlowState.UP);
            break;
        case DELETE:
            flow = flowCache.getFlow(flowId);
            logger.info("State flow: {}={}", flow.getLeft().getFlowId(), FlowState.DOWN);
            flow.getLeft().setState(FlowState.DOWN);
            flow.getRight().setState(FlowState.DOWN);
            break;
        default:
            logger.warn("Flow {} undefined reroute operation", request.getOperation());
            break;
    }
}
Also used : PathInfoData(org.openkilda.messaging.info.event.PathInfoData) MessageException(org.openkilda.messaging.error.MessageException) InfoMessage(org.openkilda.messaging.info.InfoMessage) Values(org.apache.storm.tuple.Values) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) UnroutablePathException(org.openkilda.pce.provider.UnroutablePathException) Flow(org.openkilda.messaging.model.Flow)

Example 5 with PathInfoData

use of org.openkilda.messaging.info.event.PathInfoData in project open-kilda by telstra.

the class CacheTopologyTest method buildFlowInfoData.

private FlowInfoData buildFlowInfoData(String flowId, String srcSwitch, String dstSwitch, List<PathNode> path) {
    Flow flow = new Flow();
    flow.setFlowId(flowId);
    flow.setSourceSwitch(srcSwitch);
    flow.setDestinationSwitch(dstSwitch);
    flow.setState(FlowState.UP);
    PathInfoData pathInfoData = new PathInfoData(0L, path);
    flow.setFlowPath(pathInfoData);
    ImmutablePair<Flow, Flow> immutablePair = new ImmutablePair<>(flow, flow);
    return new FlowInfoData(flowId, immutablePair, FlowOperation.CREATE, UUID.randomUUID().toString());
}
Also used : PathInfoData(org.openkilda.messaging.info.event.PathInfoData) FlowInfoData(org.openkilda.messaging.info.flow.FlowInfoData) ImmutablePair(org.openkilda.messaging.model.ImmutablePair) Flow(org.openkilda.messaging.model.Flow)

Aggregations

PathInfoData (org.openkilda.messaging.info.event.PathInfoData)39 Test (org.junit.Test)15 Flow (org.openkilda.messaging.model.Flow)13 InfoMessage (org.openkilda.messaging.info.InfoMessage)10 PathNode (org.openkilda.messaging.info.event.PathNode)10 ArrayList (java.util.ArrayList)9 FlowPayload (org.openkilda.messaging.payload.flow.FlowPayload)9 List (java.util.List)6 PathSegment (org.openkilda.model.PathSegment)5 SwitchId (org.openkilda.model.SwitchId)5 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 Values (org.apache.storm.tuple.Values)4 Driver (org.neo4j.driver.v1.Driver)4 MessageException (org.openkilda.messaging.error.MessageException)4 ImmutablePair (org.openkilda.messaging.model.ImmutablePair)4 FlowPath (org.openkilda.model.FlowPath)4 UnroutablePathException (org.openkilda.pce.provider.UnroutablePathException)4 HashMap (java.util.HashMap)3 CommandMessage (org.openkilda.messaging.command.CommandMessage)3