Search in sources :

Example 66 with Message

use of org.openkilda.messaging.Message in project open-kilda by telstra.

the class FlowServiceImpl method syncFlowCache.

/**
 * {@inheritDoc}
 */
@Override
public FlowCacheSyncResults syncFlowCache(final String correlationId) {
    LOGGER.debug("Flow cache sync: {}={}", CORRELATION_ID, correlationId);
    FlowCacheSyncRequest data = new FlowCacheSyncRequest();
    CommandMessage request = new CommandMessage(data, System.currentTimeMillis(), correlationId, Destination.WFM);
    messageConsumer.clear();
    messageProducer.send(topic, request);
    Message message = (Message) messageConsumer.poll(correlationId);
    FlowCacheSyncResponse response = (FlowCacheSyncResponse) validateInfoMessage(request, message, correlationId);
    return response.getPayload();
}
Also used : FlowCacheSyncResponse(org.openkilda.messaging.info.flow.FlowCacheSyncResponse) InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) FlowCacheSyncRequest(org.openkilda.messaging.command.flow.FlowCacheSyncRequest) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 67 with Message

use of org.openkilda.messaging.Message in project open-kilda by telstra.

the class FlowServiceImpl method flowPushUnpush.

/**
 * There are only minor differences between push and unpush .. this utility function helps
 */
private BatchResults flowPushUnpush(List<FlowInfoData> externalFlows, String correlationId, FlowOperation op) {
    LOGGER.debug("Flow {}: {}={}", op, CORRELATION_ID, correlationId);
    LOGGER.debug("Size of list: {}", externalFlows.size());
    // First, send them all, then wait for all the responses.
    // Send the command to both Flow Topology and to TE
    messageConsumer.clear();
    // used for error reporting, if needed
    ArrayList<InfoMessage> flowRequests = new ArrayList<>();
    // used for error reporting, if needed
    ArrayList<InfoMessage> teRequests = new ArrayList<>();
    for (int i = 0; i < externalFlows.size(); i++) {
        FlowInfoData data = externalFlows.get(i);
        // <-- this is what determines PUSH / UNPUSH
        data.setOperation(op);
        String flowCorrelation = correlationId + "-FLOW-" + i;
        InfoMessage flowRequest = new InfoMessage(data, System.currentTimeMillis(), flowCorrelation, Destination.WFM);
        flowRequests.add(flowRequest);
        messageProducer.send(topic, flowRequest);
        String teCorrelation = correlationId + "-TE-" + i;
        InfoMessage teRequest = new InfoMessage(data, System.currentTimeMillis(), teCorrelation, Destination.TOPOLOGY_ENGINE);
        teRequests.add(teRequest);
        messageProducer.send(topoEngTopic, teRequest);
    }
    int flow_success = 0;
    int flow_failure = 0;
    int te_success = 0;
    int te_failure = 0;
    List<String> msgs = new ArrayList<>();
    msgs.add("Total Flows Received: " + externalFlows.size());
    for (int i = 0; i < externalFlows.size(); i++) {
        String flowCorrelation = correlationId + "-FLOW-" + i;
        String teCorrelation = correlationId + "-TE-" + i;
        FlowState expectedState = (op == FlowOperation.PUSH) ? FlowState.UP : FlowState.DOWN;
        try {
            Message flowMessage = (Message) messageConsumer.poll(flowCorrelation);
            FlowStatusResponse response = (FlowStatusResponse) validateInfoMessage(flowRequests.get(i), flowMessage, correlationId);
            FlowIdStatusPayload status = response.getPayload();
            if (status.getStatus() == expectedState) {
                flow_success++;
            } else {
                msgs.add("FAILURE (FlowTopo): Flow " + status.getId() + " NOT in " + expectedState + " state: state = " + status.getStatus());
                flow_failure++;
            }
        } catch (Exception e) {
            msgs.add("EXCEPTION in Flow Topology Response: " + e.getMessage());
            flow_failure++;
        }
        try {
            // TODO: this code block is mostly the same as the previous: consolidate.
            Message teMessage = (Message) messageConsumer.poll(teCorrelation);
            FlowStatusResponse response = (FlowStatusResponse) validateInfoMessage(flowRequests.get(i), teMessage, correlationId);
            FlowIdStatusPayload status = response.getPayload();
            if (status.getStatus() == expectedState) {
                te_success++;
            } else {
                msgs.add("FAILURE (TE): Flow " + status.getId() + " NOT in " + expectedState + " state: state = " + status.getStatus());
                te_failure++;
            }
        } catch (Exception e) {
            msgs.add("EXCEPTION in Topology Engine Response: " + e.getMessage());
            te_failure++;
        }
    }
    BatchResults result = new BatchResults(flow_failure + te_failure, flow_success + te_success, msgs.stream().toArray(String[]::new));
    LOGGER.debug("Returned: ", result);
    return result;
}
Also used : FlowInfoData(org.openkilda.messaging.info.flow.FlowInfoData) FlowState(org.openkilda.messaging.payload.flow.FlowState) FlowStatusResponse(org.openkilda.messaging.info.flow.FlowStatusResponse) InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) FlowIdStatusPayload(org.openkilda.messaging.payload.flow.FlowIdStatusPayload) ArrayList(java.util.ArrayList) BatchResults(org.openkilda.northbound.service.BatchResults) InfoMessage(org.openkilda.messaging.info.InfoMessage)

Example 68 with Message

use of org.openkilda.messaging.Message in project open-kilda by telstra.

the class FlowServiceImpl method rerouteFlow.

/**
 * {@inheritDoc}
 */
@Override
public FlowPathPayload rerouteFlow(String flowId, String correlationId) {
    Flow flow = new Flow();
    flow.setFlowId(flowId);
    FlowRerouteRequest data = new FlowRerouteRequest(flow, FlowOperation.UPDATE);
    CommandMessage command = new CommandMessage(data, System.currentTimeMillis(), correlationId, Destination.WFM);
    messageConsumer.clear();
    messageProducer.send(topic, command);
    Message message = (Message) messageConsumer.poll(correlationId);
    logger.debug("Got response {}", message);
    FlowPathResponse response = (FlowPathResponse) validateInfoMessage(command, message, correlationId);
    return Converter.buildFlowPathPayloadByFlowPath(flowId, response.getPayload());
}
Also used : FlowPathResponse(org.openkilda.messaging.info.flow.FlowPathResponse) InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) Flow(org.openkilda.messaging.model.Flow) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 69 with Message

use of org.openkilda.messaging.Message in project open-kilda by telstra.

the class SwitchServiceImpl method deleteRules.

@Override
public List<Long> deleteRules(String switchId, DeleteRulesAction deleteAction, Long cookie, String correlationId) {
    LOGGER.debug("Delete switch rules request received");
    // TODO: remove  messageConsumer.clear() as a part of NB cleanup (clear isn't required)
    messageConsumer.clear();
    SwitchRulesDeleteRequest data = new SwitchRulesDeleteRequest(switchId, deleteAction, cookie);
    CommandMessage request = new CommandWithReplyToMessage(data, System.currentTimeMillis(), correlationId, Destination.CONTROLLER, northboundTopic);
    messageProducer.send(floodlightTopic, request);
    Message message = messageConsumer.poll(correlationId);
    SwitchRulesResponse response = (SwitchRulesResponse) validateInfoMessage(request, message, correlationId);
    return response.getRuleIds();
}
Also used : Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) CommandWithReplyToMessage(org.openkilda.messaging.command.CommandWithReplyToMessage) SwitchRulesResponse(org.openkilda.messaging.info.switches.SwitchRulesResponse) SwitchRulesDeleteRequest(org.openkilda.messaging.command.switches.SwitchRulesDeleteRequest) CommandWithReplyToMessage(org.openkilda.messaging.command.CommandWithReplyToMessage) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 70 with Message

use of org.openkilda.messaging.Message in project open-kilda by telstra.

the class SwitchServiceImpl method connectMode.

@Override
public ConnectModeRequest.Mode connectMode(ConnectModeRequest.Mode mode, String correlationId) {
    LOGGER.debug("Set/Get switch connect mode request received: mode = {}", mode);
    ConnectModeRequest data = new ConnectModeRequest(mode);
    CommandMessage request = new CommandWithReplyToMessage(data, System.currentTimeMillis(), correlationId, Destination.CONTROLLER, northboundTopic);
    messageProducer.send(floodlightTopic, request);
    Message message = messageConsumer.poll(correlationId);
    ConnectModeResponse response = (ConnectModeResponse) validateInfoMessage(request, message, correlationId);
    return response.getMode();
}
Also used : ConnectModeRequest(org.openkilda.messaging.command.switches.ConnectModeRequest) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) CommandWithReplyToMessage(org.openkilda.messaging.command.CommandWithReplyToMessage) CommandWithReplyToMessage(org.openkilda.messaging.command.CommandWithReplyToMessage) CommandMessage(org.openkilda.messaging.command.CommandMessage) ConnectModeResponse(org.openkilda.messaging.info.switches.ConnectModeResponse)

Aggregations

Message (org.openkilda.messaging.Message)71 CommandMessage (org.openkilda.messaging.command.CommandMessage)55 InfoMessage (org.openkilda.messaging.info.InfoMessage)55 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)29 Test (org.junit.Test)25 IOException (java.io.IOException)11 Values (org.apache.storm.tuple.Values)10 CtrlRequest (org.openkilda.messaging.ctrl.CtrlRequest)6 CtrlResponse (org.openkilda.messaging.ctrl.CtrlResponse)6 FlowIdStatusPayload (org.openkilda.messaging.payload.flow.FlowIdStatusPayload)6 CommandData (org.openkilda.messaging.command.CommandData)5 RequestData (org.openkilda.messaging.ctrl.RequestData)5 FlowResponse (org.openkilda.messaging.info.flow.FlowResponse)5 CommandWithReplyToMessage (org.openkilda.messaging.command.CommandWithReplyToMessage)4 DumpStateResponseData (org.openkilda.messaging.ctrl.DumpStateResponseData)4 IslInfoData (org.openkilda.messaging.info.event.IslInfoData)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 BaseInstallFlow (org.openkilda.messaging.command.flow.BaseInstallFlow)3 FlowCreateRequest (org.openkilda.messaging.command.flow.FlowCreateRequest)3 FlowGetRequest (org.openkilda.messaging.command.flow.FlowGetRequest)3